Encryption and compression, Huffman encoding and decoding

Source: Internet
Author: User
Tags comparison table ming

Summary: Each character appearing in the text is encoded by counting the frequency of each character appearing in an article (or a book), such as the occurrence of a 100-time letter A. This encoding is characterized by the higher the frequency of the characters, the shorter the encoding length. With such a character, encoding table, you can send "ciphertext"! For a chestnut: in the morning, when I saw a news article, Blablabla content was unimportant. As follows:

Apple Inc. plans to break with its recent pattern of overhauling the design of its flagship IPhone every-years, and MA Ke only subtle changes in the models it would release this fall, according to people familiar with the matter.
Among other things, those people said, Apple ' s newest phones would maintain the current 4.7-inch and 5.5-inch displays. Those is the sizes of the Larger-display models Apple introduced in, and refreshed with newer models last fall.
The biggest planned change in this year's phones is the removal of the headphone plug, which would make the phone thinner a nd improve its water resistance, said people with that matter.
The Lightning connector would serve double-duty as a port for charging the phone and for connecting headphones, they said. KGI Securities analyst Ming-chi Kuo said he expects the new iphone to being one millimeter thinner than the current iphone.
Apple plans bigger design changes for, the 10th anniversary of the original IPhone. Those changes could include an Edge-to-edge organic light-emitting diode, or oleds, screen and eliminating the home button By building the fingerprint sensor into the display, according to people familiar with the matter.
An Apple spokeswoman declined to comment.
In the past, Apple have introduced new iPhones on a "Ticktock" cycle. Apple delivers major design changes every other year-the ' tick ' years-followed by software improvements and hardware Refin Ements in the "Tock" years.
It isn ' t clear whether this year's shift is a temporary or permanent departure from the this pattern. Either, it comes at a precarious moment for the IPhone, Apple's most important product, accounting for two-thirds of T He company ' s revenue.
Apple is dealing with the first decline on iPhone sales in the product ' s history as demand slows and once-torrid the S Uch as China cool.
Advertisement
The introduction of Larger-display phones in triggered a surge in sales, with IPhone sales rising 37% in the fiscal y Ear ending September 2015. In the prior year, when Apple introduced the iphone 5S with a near identical design to the iphone 5, iphone sales increase D 13%.
At a meeting for Apple executive last month, one of the company's china-based engineers asked why this year's model LA Cked A major design change in keeping with Apple ' s usual two-year cycle. The answer, one person at the meeting recalled, is, the new technology in the pipeline would take time to implement.
Apple Coverage
China bites Apple
Apple Outlines Siri improvements
Dear Apple, make the IPhone Smarter
Siri:once a Flake, now Key to Apple's future
People familiar with the matter said some features so Apple hopes to integrate into iPhones, such as curved screens, wer En ' t ready-for-this-year ' s models.
Previous Big design changes to the phone helped create buzz around the new models and spur sales by enticing existing IPhO NE customers to upgrade. Apple ' s latest phones-the iPhone 6S and 6S Plus-haven ' t generated as much excitement, in part because they closely RESEMBL E The previous year ' s models.
In a interview on CNBC last month, Apple chief Executive Tim Cook said that there was "great innovation" in the pipeline F or future iPhones that would drive customers to upgrade. "We're going to give you things so you can ' t live without so you just don ' t know you need today," Mr Cook said.
In a note to clients last week, credits Suisse analyst Kulbinder Garcha said he expects "muted" sales increases for the for Thcoming models because he expects them to is a "modest upgrade" to the existing phones. Mr Garcha said he expects a "super cycle" for the following year.
Horace Dediu, founder of Asymco, an independent analysis firm focused on the mobile industry, said many consumers buy new Phones when they is due for a upgrade under the terms of their wireless plan, without much concern for new features or D Esign changes. While other companies try to entice consumers to upgrade phones with new features, he said Apple "marches to the beat of a Different drummer. "
Apple had delivered meaningful improvements to the iPhone even in years when it didn ' t change the phone's look. For example, it added a fingerprint sensor to the IPhone 5S, but that didn ' t alter the look of the device.
The models introduced, while the same size as their predecessors, included faster processors, new Touch-screen F Eatures and better cameras. Apple tried to capture the changes with it marketing slogan for IPhone 6S and 6S Plus: "The only thing that's changed is Everything. "
For years, Apple chief Design Officer Jony Ive have expressed a desire for the iPhone to appear like a single sheet of glas s, according to people familiar with the matter. The current design ideas for the IPhones is expected to push the handsets in that direction by eliminating much of t He bezel around the display with the OLED screen.
Apple hasn ' t completed the designs for next year's phones, so it's possible that these ideas could not be implemented, they said.
Write to Daisuke Wakabayashi @ [email protected] and Eva Dou at [email protected]

By counting the character frequency and coding, we get the comparison table:

Character: Frequency: 822 Code: 110
Character:% frequency: 2 code: 00101100101
Character: ' Frequency: 3 code: 11100011100
Character:, Frequency: 44 Code: 1110000
Character:-Frequency: 14 Code: 111011101
Character:. Frequency: 43 Code: 1010101
Character: 0 Frequency: 6 Code: 1110001100
Character: 1 Frequency: 7 Code: 001000000
Character: 2 frequency: 5 Code: 0010111110
Character: 3 Frequency: 2 Code: 00101100110
Character: 4 Frequency: 3 Code: 11100011101
Character: 5 frequency: 6 Code: 1110001101
Character: 6 Frequency: 4 Code: 0010000100
Character: 7 frequency: 4 Code: 0010000101
Character:: Frequency: 2 code: 00101100111
Character: @ Frequency: 2 Code: 00101101000
Character: A frequency: 30 Code: 0000010
Character: B frequency: 2 Code: 00101101001
Character: C frequency: 12 Code: 111000100
Character: D frequency: 8 Code: 001000001
Character: E frequency: 5 Code: 0010111111
Character: F frequency: 4 Code: 0010000110
Character: G frequency: 3 Code: 11100011110
Character: H frequency: 1 Code: 001011010110
Character: I Frequency: 9 Code: 001011011
Character: J frequency: 1 Code: 001011010111
Character: K frequency: 4 Code: 0010000111
Character: L frequency: 3 Code: 11100011111
Character: M frequency: 4 Code: 0010110000
Character: N frequency: 2 Code: 00101101010
Character: O frequency: 5 Code: 1010100000
Character: P frequency: 26 Code: 11101100
Character: S frequency: 12 Code: 111000101
Character: T frequency: 10 code: 001011100
Character: W frequency: 5 Code: 1010100001
Character: A frequency: 277 code: 0100
Character: B Frequency: 31 Code: 0000011
Character: C Frequency: 124 Code: 00001
Character: D Frequency: 150 Code: 10011
Character: E Frequency: 583 Code: 011
Character: F Frequency: 64 code: 001001
Character: G Frequency: 90 Code: 101011
Character: H Frequency: 233 Code: 11110
Character: I frequency: 292 Code: 1000
Character: J Frequency: 5 Code: 1010100010
Character: K Frequency: 27 Code: 11101101
Character: L Frequency: 159 Code: 10100
Character: M Frequency: 99 Code: 111010
Character: N Frequency: 291 Code: 0101
Character: O Frequency: 255 code: 0001
Character: P Frequency: 144 Code: 10010
Character: R frequency: 235 Code: 11111
Character: s frequency: 270 code: 0011
Character: T frequency: 344 code: 1011
Character: U frequency: 93 Code: 111001
Character: V Frequency: 32 Code: 0010001
Character: W Frequency: 61 Code: 000000
Character: X frequency: 13 Code: 111011100
Character: Y frequency: 67 Code: 001010
Character: Z Frequency: 5 code: 1010100011
Character:-Frequency: 4 Code: 0010110001
Character: ' Frequency: 21 Code: 10101001
Character: "Frequency: 10 code: 001011101
Character: "Frequency: 10 code: 001011110

What do you mean by this series of "ciphertext"? 1110001000000111010010100000111010101000010001111111010010011 directly on the code. Please use the PYTHON3 interpreter.
Class Node (object): Def __init__ (self, freq): Self.freq = freq Self.left = None Self.right = None Self.father = None def isleft (self): return self.father.left = = Selfdef Createhuffmantree (C): n = Len (        C) Q = c[:] for I in range (n-1): Q.sort (Key=lambda x:x.freq) x = Q.pop (0) y = q.pop (0)        node = node (x.freq + y.freq) node.left = x node.right = y x.father = node Y.father = node Q.append (node) q[0].father = None return q[0]def pretraverse (root): if Root==none:return prin T (root.freq) Pretraverse (root.left) Pretraverse (root.right) def huffmanencoding (C, root): CodeList = ["] * le                N (c) for I in Range (Len (c)): Tmpnode = C[i] while Tmpnode! = Root:if Tmpnode.isleft ():  Codelist[i] = "0" + codelist[i] else:codelist[i] = "1" + codelist[i] Tmpnode = Tmpnode.father retUrn codelistdef Huffmandecode (code, CODINGDICT): res = "" Decodedict = {Value:key for key, value in Codingdict.item S ()} Tmpcode = "" while Code:tmpcode + = code[0] Code = code[1:] ch = decodedict.get (Tmpcode, N    one) If ch:res = res + ch Tmpcode = "" Return resdef WordCount (strText): Chdict = {}    For ch in strtext:if chdict.get (CH, None): chdict[ch] + = 1 Else:chdict[ch] = 1 Return list (Map (lambda x: (X[0], x[1]), Chdict.items ()))
So, the solution is, the above article as input, to get the character encoding table after the call decoding program is good!
StrText = "" "Apple Inc. plans to break with it recent pattern of overhauling the design of its flagship IPhone every Years, and make only subtle changes in the models it would release this fall, according-people familiar with the MA Tter. Among other things, those people said, Apple ' s newest phones would maintain the current 4.7-inch and 5.5-inch displays. Those is the sizes of the Larger-display models Apple introduced in, and refreshed with newer models last fall. The biggest planned change in this year's phones is the removal of the headphone plug, which would make the phone thinner a nd improve its water resistance, said people with that matter. The Lightning connector would serve double-duty as a port for charging the phone and for connecting headphones, they said. KGI Securities analyst Ming-chi Kuo said he expects the new iPhone to being one millimeter thinner than the current Iphone.ap PLE plans bigger design changes for, the 10th anniversary of the original IPhone.Those changes could include an Edge-to-edge organic light-emitting diode, or oleds, screen and eliminating the home button By building the fingerprint sensor into the display, according to people familiar with the matter. An Apple spokeswoman declined to comment. In the past, Apple have introduced new iPhones on a "Ticktock" cycle. Apple delivers major design changes every other year-the ' tick ' years-followed by software improvements and hardware Refin Ements in the "Tock" years. It isn ' t clear whether this year's shift is a temporary or permanent departure from the this pattern. Either, it comes at a precarious moment for the IPhone, Apple's most important product, accounting for two-thirds of T He company ' s revenue. Apple is dealing with the first decline on iPhone sales in the product ' s history as demand slows and once-torrid the S Uch as China cool.  Advertisementthe introduction of Larger-display phones in triggered a surge in sales, with the IPhone sales rising 37% in The fiscal year Ending September 2015. In the prior year, when Apple introduced the iphone 5S with a near identical design to the iphone 5, iphone sales increase D 13%. At a meeting for Apple executive last month, one of the company's china-based engineers asked why this year's model LA Cked A major design change in keeping with Apple ' s usual two-year cycle. The answer, one person at the meeting recalled, is, the new technology in the pipeline would take time to implement. Apple Coverage China bites Apple Apple outlines Siri improvements Dear Apple and make the IPhone Smarter S Iri:once a Flake, now Key to Apple's futurepeople familiar with the matter said some features this Apple hopes to Integra Te into iPhones, such as curved screens, and weren ' t ready for the year ' s models. Previous Big design changes to the phone helped create buzz around the new models and spur sales by enticing existing IPhO NE customers to upgrade. Apple ' s latest phones-the iPhone 6S and 6S Plus-haven ' t generatedAs much excitement, in part because they closely resemble the previous of year ' s models. In a interview on CNBC last month, Apple chief Executive Tim Cook said that there was "great innovation" in the pipeline F or future iPhones that would drive customers to upgrade. "We're going to give you things so you can ' t live without so you just don ' t know you need today," Mr Cook said. In a note to clients last week, credits Suisse analyst Kulbinder Garcha said he expects "muted" sales increases for the for Thcoming models because he expects them to is a "modest upgrade" to the existing phones. Mr Garcha said he expects a "super cycle" for the following year. Horace Dediu, founder of Asymco, an independent analysis firm focused on the mobile industry, said many consumers buy new Phones when they is due for a upgrade under the terms of their wireless plan, without much concern for new features or D Esign changes. While other companies try to entice consumers to upgrade phones with new features, hE said Apple "marches to the beat of a different drummer." Apple had delivered meaningful improvements to the iPhone even in years when it didn ' t change the phone's look. For example, it added a fingerprint sensor to the IPhone 5S, but that didn ' t alter the look of the device. The models introduced, while the same size as their predecessors, included faster processors, new Touch-screen F Eatures and better cameras. Apple tried to capture the changes with it marketing slogan for IPhone 6S and 6S Plus: "The only thing that's changed is Everything. " For years, Apple chief Design Officer Jony Ive have expressed a desire for the iPhone to appear like a single sheet of glas s, according to people familiar with the matter. The current design ideas for the IPhones is expected to push the handsets in that direction by eliminating much of t He bezel around the display with the OLED screen. Apple hasn ' t completed the designs for next year's phones, so it's possible that these ideas mayNot being implemented, they said. Write to Daisuke Wakabayashi @ [email protected] and Eva Dou at [email protected] "" "Chlist = WordCount (str Text) Chlist.sort (Key=lambda x:x[0]) # print (chlist) C = [Node (x[1]) for x in chlist]root = Createhuffmantree (C) # Validate the resulting tree with design one to # Pretraverse (root) codeList = Huffmanencoding (C, root) codingdict = {}for ch, code in ZIP (Chlist, codeList): codingdict [ch[0]] = code print ("character:", ch[0], "Frequency:", ch[1], "code:", code) code = "111000100000011101001010000011101010100001000111 1111010010011 "res = Huffmandecode (code, codingdict) print (" Decode: ", code," = = ", res)
Oh, that's Hello World!!!!!!

Encryption and compression, Huffman encoding and decoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.