├── README.md ├── bigBitField.py ├── commandline.py ├── config.py ├── exampledata ├── example.jpg ├── example.png ├── example.zip ├── example1A.txt ├── example1B.txt ├── example2A.txt ├── example2B.txt ├── example3A.txt ├── example3B.txt ├── markovChain.json └── markovChain2.json ├── fixedSizeCode.py ├── fixedSizeDecode.py ├── fixedSizeExamples.py ├── markov.py ├── utils.py └── variableSizeCode.py /README.md: -------------------------------------------------------------------------------- 1 | ## Text steganography 2 | 3 | Code for *"An Approach for Text Steganography Based on Markov Chains"*, JAIIO / WSegI 2012 4 | http://www.41jaiio.org.ar/sites/default/files/3_WSegI_2012.pdf 5 | 6 | Abstract: *A text steganography method based on Markov chains is introduced, together with a reference implementation. This method allows for information hiding in texts that are automatically generated following a given Markov model. Other Markov - based systems of this kind rely on big simplifications of the language model to work, which produces less natural looking and more easily detectable texts. The method described here is designed to generate texts within a good approximation of the original language model provided.* 7 | 8 | By Hernan Moraldo 9 | - http://linkedin.com/in/hmoraldo 10 | - http://www.hernan.moraldo.com.ar 11 | 12 | 13 | ### Online demo 14 | 15 | This Github repository contains the Python prototype that was presented together with the paper. Recently, **Jackson Thuraisamy** implemented a text steganography library in JavaScript that is adapted from the paper linked above. 16 | 17 | Please refer to the following project to see an online demo of this method: 18 | 19 | - Jackson Thuraisamy's JavaScript code: https://github.com/jthuraisamy/markovTextStego.js 20 | - Jackson's online demo: http://jthuraisamy.github.io/markovTextStego.js/ 21 | 22 | 23 | ## Usage: 24 | 25 | 26 | There are two possible modes for encoding and decoding data into stego texts: 27 | 28 | 1- unigram mode (every state in the Markov chain is a single word) 29 | 2- bigram mode (every state in the Markov chain is a bigram) 30 | 31 | These two modes are incompatible with each other. A message encoded in the bigram mode, 32 | can't be decoded with the unigram mode. 33 | 34 | ### Commands for unigram mode: 35 | 36 | To create a Markov chain: 37 | 38 | `python commandline.py --wordsPerState 1 createMarkov data/warandpeace.txt data/markovChain.json` 39 | 40 | to test the Markov chain: 41 | 42 | `python commandline.py testMarkov data/markovChain.json any` 43 | 44 | to generate a text out of some input file input.data: 45 | 46 | `python commandline.py encodeFullText --markovInput data/markovChain.json --wordsPerState 1 input.data encoded.txt` 47 | 48 | to decode a text file encoded.txt to the original input data: 49 | 50 | `python commandline.py decodeFullText --markovInput data/markovChain.json --wordsPerState 1 encoded.txt output.data` 51 | 52 | Other commands are described in the top comments at commandline.py. 53 | 54 | 55 | 56 | ### Commands for bigram mode: 57 | 58 | To create a Markov chain: 59 | 60 | `python commandline.py --wordsPerState 2 createMarkov data/warandpeace.txt data/markovChain2.json` 61 | 62 | to test the Markov chain: 63 | 64 | `python commandline.py testMarkov data/markovChain2.json any` 65 | 66 | to generate a text out of some input file input2.data: 67 | 68 | `python commandline.py encodeFullText --markovInput data/markovChain2.json --wordsPerState 2 input2.data encoded2.txt` 69 | 70 | to decode a text file encoded2.txt to the original input data: 71 | 72 | python commandline.py decodeFullText --markovInput data/markovChain2.json --wordsPerState 2 encoded2.txt output2.data` 73 | 74 | Other commands are described in the top comments at commandline.py. 75 | 76 | 77 | -------------------------------------------------------------------------------- /bigBitField.py: -------------------------------------------------------------------------------- 1 | "defines a big bit field object" 2 | import utils 3 | import math 4 | 5 | """ 6 | a class for managing big amounts of bits (these bits are internally stored as bytes, except in the left and right extremes) 7 | """ 8 | class BigBitField: 9 | 10 | def __init__(self, data = None, dataIsBytes = True): 11 | if data is None: 12 | data = [] 13 | 14 | self.lastBitsCache = "" 15 | 16 | if dataIsBytes: 17 | self.firstBitsCache = "" 18 | self.remainingBytes = data 19 | else: 20 | self.firstBitsCache = data 21 | self.remainingBytes = [] 22 | 23 | 24 | def copy(self): 25 | bitField = BigBitField() 26 | bitField.firstBitsCache = self.firstBitsCache 27 | bitField.lastBitsCache = self.lastBitsCache 28 | bitField.remainingBytes = list(self.remainingBytes) 29 | return bitField 30 | 31 | """ 32 | internal; we store data as bytes and as a string with the explicit bits... this function extracts n bytes into the 33 | string, and converts them to ascii 1 and 0 that is easy to operate with 34 | """ 35 | def popBytesToBitsCache(self, bytesToPop): 36 | if len(self.remainingBytes) < bytesToPop: 37 | raise RuntimeError("not enough bytes for popToBits operation") 38 | 39 | for x in range(bytesToPop): 40 | byte = self.remainingBytes.pop(0) 41 | bits = utils.toBinary(byte, 8) 42 | self.firstBitsCache = self.firstBitsCache + bits 43 | 44 | def totalFieldLen(self): 45 | return len(self.firstBitsCache) + len(self.remainingBytes) * 8 + len(self.lastBitsCache) 46 | 47 | 48 | "internal: gets at least n bits extra ready in firstBitsCache" 49 | def getNBitsReady(self, bitsCount): 50 | if self.totalFieldLen() < bitsCount: 51 | raise RuntimeError("not enough bits for getNBitsReady") 52 | else: 53 | while len(self.firstBitsCache) < bitsCount: 54 | # push bytes to bits 55 | bytesToGet = int(math.ceil((bitsCount - len(self.firstBitsCache)) / 8.0)) 56 | bytesToGet = min(len(self.remainingBytes), bytesToGet) 57 | self.popBytesToBitsCache(bytesToGet) 58 | 59 | # if no more bytes, move all bits from one extreme to the other 60 | # (even if this means getting more bits ready than what the user asked for) 61 | if self.remainingBytes == []: 62 | self.firstBitsCache = self.firstBitsCache + self.lastBitsCache 63 | self.lastBitsCache = "" 64 | 65 | "get n bits from the field, but don't change the field" 66 | def getFirstNBits(self, bitsCount): 67 | self.getNBitsReady(bitsCount) 68 | 69 | return self.firstBitsCache[0:bitsCount] 70 | 71 | "pop the first n bits from the field" 72 | def popFirstNBits(self, bitsCount): 73 | self.getNBitsReady(bitsCount) 74 | firstNBits = self.firstBitsCache[0:bitsCount] 75 | self.firstBitsCache = self.firstBitsCache[bitsCount:] 76 | 77 | return firstNBits 78 | 79 | "push a number of bits, as in a stack (from the top or first bits)" 80 | def pushNBits(self, bits): 81 | self.firstBitsCache = bits + self.firstBitsCache 82 | while len(self.firstBitsCache) >= 8: 83 | idx = len(self.firstBitsCache) - 8 84 | self.remainingBytes.insert(0, utils.fromBinary(self.firstBitsCache[idx:])) 85 | self.firstBitsCache = self.firstBitsCache[0:idx] 86 | 87 | "push a number of bits, as in a queue (from the bottom or last bits)" 88 | def pushQueueNBits(self, bits): 89 | self.lastBitsCache = self.lastBitsCache + bits 90 | while len(self.lastBitsCache) >= 8: 91 | idx = 8 92 | self.remainingBytes.append(utils.fromBinary(self.lastBitsCache[0:idx])) 93 | self.lastBitsCache = self.lastBitsCache[idx:] 94 | 95 | # returns all bytes if the data stored can be returned as bytes 96 | def getAllBytes(self): 97 | if self.firstBitsCache != "" or self.lastBitsCache != "": 98 | raise RuntimeError("can't getAllBytes from bitField; not all data stored in bytes now") 99 | else: 100 | return self.remainingBytes 101 | 102 | 103 | if __name__ == '__main__': 104 | print "testing bigBitField.py" 105 | # this is "01000110 01011010 11111111" 106 | bits = BigBitField([70, 90, 255]) 107 | print "A:" 108 | print bits.totalFieldLen() == 24 109 | print "B:" 110 | print bits.getFirstNBits(8) == "01000110" 111 | print "B2:" 112 | print bits.popFirstNBits(0) == "" 113 | print "B3:" 114 | print bits.getFirstNBits(0) == "" 115 | print "C:" 116 | print bits.popFirstNBits(3) == "010" 117 | print "D:" 118 | print bits.getFirstNBits(6) == "001100" 119 | print "E:" 120 | print bits.popFirstNBits(8) == "00110010" 121 | print "F:" 122 | print bits.totalFieldLen() == 13 123 | print "G:" 124 | print bits.getFirstNBits(6) == "110101" 125 | print "H:" 126 | print bits.popFirstNBits(4) == "1101" 127 | print "I:" 128 | print bits.popFirstNBits(7) == "0111111" 129 | print "J:" 130 | print bits.totalFieldLen() == 2 131 | print "K:" 132 | print bits.popFirstNBits(2) == "11" 133 | print "L:" 134 | print bits.totalFieldLen() == 0 135 | print "M:" 136 | bits.pushNBits("010") 137 | bits.pushNBits("1110111111") 138 | print bits.totalFieldLen() == 13 139 | print bits.firstBitsCache == "11101" 140 | print bits.popFirstNBits(13) == "1110111111010" 141 | print bits.totalFieldLen() == 0 142 | print "N:" 143 | bits.pushQueueNBits("11111") 144 | bits.pushQueueNBits("1010") 145 | bits.pushQueueNBits("001100") 146 | bits.pushQueueNBits("1100") 147 | bits.pushNBits("1100") 148 | bits.pushNBits("111111100111") 149 | # bits should be "111111100111 1100 11111 1010 001100 1100" 150 | print bits.totalFieldLen() == 35 151 | print bits.popFirstNBits(10) == "1111111001" 152 | print bits.popFirstNBits(4) == "1111" 153 | print bits.popFirstNBits(7) == "0011111" 154 | print bits.popFirstNBits(7) == "1010001" 155 | print bits.popFirstNBits(7) == "1001100" 156 | print "done" 157 | 158 | -------------------------------------------------------------------------------- /commandline.py: -------------------------------------------------------------------------------- 1 | # create simple markov chain: 2 | # python commandline.py --wordsPerState 1 createMarkov data/warandpeace.txt data/markovChain.json 3 | # create markov chain with bigrams: 4 | # python commandline.py --wordsPerState 2 createMarkov data/warandpeace.txt data/markovChain2.json 5 | 6 | # test any markov chain: 7 | # python commandline.py testMarkov data/markovChain.json any 8 | 9 | # generate texts using both markov chains: 10 | # python commandline.py --wordsPerState 1 genTextWithMarkov data/markovChain.json any 11 | # python commandline.py --wordsPerState 2 genTextWithMarkov data/markovChain2.json any 12 | 13 | # simple encode decode to json file: 14 | # python commandline.py encode --markovInput data/markovChain.json tests/utils.pyc.orig.1 tests/encoded.json 15 | # python commandline.py decode --markovInput data/markovChain.json tests/encoded.json tests/utils.pyc.1 16 | # test with: diff tests/utils.pyc.orig.1 tests/utils.pyc.1 17 | 18 | # encode decode to json file, using bigrams: 19 | # python commandline.py encode --markovInput data/markovChain2.json --wordsPerState 2 tests/utils.pyc.orig.1 tests/encoded2.json 20 | # python commandline.py decode --markovInput data/markovChain2.json --wordsPerState 2 tests/encoded2.json tests/utils.pyc.1 21 | 22 | # encode decode to txt file, using bigrams: 23 | # python commandline.py encodeFullText --markovInput data/markovChain2.json --wordsPerState 2 tests/utils.pyc.orig.1 tests/encoded2.txt 24 | # python commandline.py decodeFullText --markovInput data/markovChain2.json --wordsPerState 2 tests/encoded2.txt tests/utils.pyc.1 25 | 26 | import argparse 27 | import markov 28 | import utils 29 | import variableSizeCode 30 | 31 | # handle args 32 | parser = argparse.ArgumentParser(description='Create markov chain, encode or decode') 33 | parser.add_argument('mode', metavar='mode', type=str, choices=["createMarkov", "testMarkov", "genTextWithMarkov", "encode", "decode", "encodeFullText", "decodeFullText"], 34 | help='select mode to use') 35 | parser.add_argument('input', metavar='input', type=str, 36 | help='input file to use') 37 | parser.add_argument('output', metavar='output', type=str, 38 | help='output file to use') 39 | parser.add_argument('--markovInput', metavar='file', type=str, 40 | help='for encode and decode modes, markov chain to use for input') 41 | parser.add_argument('--wordsPerState', metavar='wordsPerState', choices=["1", "2"], 42 | help='# of words in the input state for the markov chain') 43 | 44 | args = parser.parse_args() 45 | 46 | 47 | mode = args.mode 48 | inputFile = args.input 49 | outputFile = args.output 50 | 51 | wordsPerState = args.wordsPerState 52 | if wordsPerState == "1" or wordsPerState == "2": wordsPerState = int(wordsPerState) 53 | if wordsPerState == None: wordsPerState = 1 54 | 55 | if mode == "createMarkov": 56 | print "creating markov chain" 57 | print "using wordsPerState = " + repr(wordsPerState) 58 | markov.createMarkovChainFromFile(inputFile, outputFile, wordsPerState) 59 | print "done" 60 | elif mode == "testMarkov": 61 | print "testing markov chain" 62 | markov.testMarkovChain(inputFile) 63 | print "done" 64 | elif mode == "genTextWithMarkov": 65 | print "generating text using markov chain" 66 | print "using wordsPerState = " + repr(wordsPerState) 67 | print(utils.wordListToText(markov.generateTextUsingMarkovChain(inputFile, wordsPerState))) 68 | print "done" 69 | elif mode == "encode": 70 | markovInputFile = args.markovInput 71 | print "encoding file (number to text) using markov chain, saving as json" 72 | variableSizeCode.encodeDataFromFile(inputFile, outputFile, markovInputFile, False, wordsPerState) 73 | print "done" 74 | elif mode == "decode": 75 | markovInputFile = args.markovInput 76 | print "decoding file (json text to number) using markov chain" 77 | variableSizeCode.decodeDataFromFile(inputFile, outputFile, markovInputFile, False, wordsPerState) 78 | print "done" 79 | elif mode == "encodeFullText": 80 | markovInputFile = args.markovInput 81 | print "encoding file (number to text) using markov chain, saving as txt" 82 | variableSizeCode.encodeDataFromFile(inputFile, outputFile, markovInputFile, True, wordsPerState) 83 | print "done" 84 | elif mode == "decodeFullText": 85 | markovInputFile = args.markovInput 86 | print "decoding file (text in .txt to number) using markov chain" 87 | variableSizeCode.decodeDataFromFile(inputFile, outputFile, markovInputFile, True, wordsPerState) 88 | print "done" 89 | 90 | 91 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # CONFIG 2 | startSymbol = "" 3 | 4 | 5 | # used by many tests 6 | testMarkov = [ 7 | [startSymbol, [ ["A", [1, 3]], ["B", [1, 3]], ["C", [1, 3]] ]], 8 | ["A", [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 9 | ["B", [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 10 | ["C", [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]] 11 | ] 12 | 13 | testMarkov2 = [ 14 | [[startSymbol, startSymbol], [ ["A", [1, 3]], ["B", [1, 3]], ["C", [1, 3]] ]], 15 | [[startSymbol, "A"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 16 | [[startSymbol, "B"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 17 | [[startSymbol, "C"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 18 | [["A", "A"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 19 | [["A", "B"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 20 | [["A", "C"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 21 | [["B", "A"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 22 | [["B", "B"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 23 | [["B", "C"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 24 | [["C", "A"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 25 | [["C", "B"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]], 26 | [["C", "C"], [ ["A", [1, 4]], ["B", [1, 4]], ["C", [1, 4]], [startSymbol, [1, 4]] ]] 27 | ] 28 | 29 | 30 | -------------------------------------------------------------------------------- /exampledata/example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmoraldo/markovTextStego/f18fb7c6867438a5e589957968b6769fef2c3add/exampledata/example.jpg -------------------------------------------------------------------------------- /exampledata/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmoraldo/markovTextStego/f18fb7c6867438a5e589957968b6769fef2c3add/exampledata/example.png -------------------------------------------------------------------------------- /exampledata/example.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmoraldo/markovTextStego/f18fb7c6867438a5e589957968b6769fef2c3add/exampledata/example.zip -------------------------------------------------------------------------------- /exampledata/example1A.txt: -------------------------------------------------------------------------------- 1 | Be limited and secondly because Pierre suddenly realized. Und die and secondly. Monotonous sound of the man who too late. Monsieur Kiril Andreevich nicknamed the hour later grasped the Russian commanders. Dressed for the new building with a year period of the two or an example. Reveries about four months continuously as if that morning sun. What prayer book in their suites that all stopped. And cannon ball at the science of buckwheat cooked their trust. Then he took him in a trot. Blushed for various classes went into all all these causes events and coughed. Saving Russia. Go to Saltykov. But a young count for a pair of some for nothing. You have some pigeons. In which was the faces of it be clear conception of the questions were putting his new pack of nervous. And a stately pose. Majestic expression showed a contemptuous smile that the devil himself always spoke with the Knoll there is Lise about. And pillaging continue. That's not carry away and considerations his caleche. She is one general remained with its own. I am so out. I have combined to form of which Tikhon Shcherbaty was also. We may. Slow awakening. She herself in his frigid laugh. And poured out of Madeira. And. He was a long ago. Twice he came out and raised his Liebchen to do not yet quite easy to tell you. Approached Yaroslavl. Is continually turning to us to this new power. The French historians who shouts behind means of the newly commissioned to help adopting smaller and not dare to death. Who is the large room. Which Rostov stopped Austria's cackle and bewildered Mitenka. Slipped. A country. Has been made a big house in the passage they said the French with his head off the land and geniality with curiosity. The near the foot. And demanded. At the governess rose to do so kind of straw covered piles. And Sonya. For the count the fight now assembled in early youth and that should the count had exhibited a strong when he talked of quiet refuge. And again fall for. Just like a removal into the old prince Andrew. You shan't be unable to gratify the duration of the way and starting to his wife explaining why did not to Ermolov was an unexpected reverberation in every way. He has ordered a maiden in Moscow. Marya Dmitrievna's room cloudy with self adulation. And never since then my fault. When the French dragoons with disordered foe. Answered the place. Several hundred on the Shevardino Redoubt was lucky for. The lines. Pierre realize the living her room and the old creature of the side. Write or another. And then he knew it. If you know Thou. Your Father. To take her sat dozing. But I am always aches and the talk in his hearer since the orders where crowds of fire did not available for the damp or easy. And constantly shaping of reason they greeted Prince Auersperg. They have been more often. He asked you two halves one another. I made by a fool. But he remembered these men are interested him. Helene had come quite far through which he was suddenly acquire a cadet to pass. Uncertain whether the peace but that everybody was convinced that he had ridden up in alarm on. Noticing that it was in chief temptation. But he would begin to upbraid him jump down cushions on the muddy field in the long It's not. Without understanding how sensitive character and should be caught him. And the general. Stepped from the very reason for a great man in Pierre's peasants were drowned all that had been formerly he cannot be no betrothed And all manfully if dazzled by serfs carrying a whisper. Occasionally a gray haired general sat bending his subordinates demanded an example. One desire. But perhaps both cavalry a devout and sent by. You must behave yourself. But he went into three months. The bed he was so to become even if we often spoke to her eyes bent over it is possible. Where an overgrown with a gambler. And it was brought him at him seemed calm faces. Whatever I am to her brother promised not attain peace. Added to avail themselves in my Cossack. And at the tension of the goal and in the footman conducted him the word to read to say What he looked at Countess. Put all their arrival he was particularly so I'll go Natasha and ascending on being stronger it will make me were dragging it should go to the candle beside him almost before now an expression of the dead men on like Princess Mary looked at the historians declare his own. Rostov had sunk in the middle of severity of laughter grew their way if unable to a dress puffed up a look up to hide behind joyfully welcomed by fear of Prussia sooner or that. Princess Mary was adjusting his coachman who was. And vestibule to say. Because Kutuzov and began irresolutely beside her reticule a good. With a row of no one at least of an hour. When he descends for a diplomatic corps out of jurisprudence. Of joy in alliance a softening of French Guards. And setting fire. His hand with her. Not restrain themselves in the roof of life as an advanced into unknown essence. In chief. And acted thus an honorable Count had turned pale swollen faces in the fire the protectors of his arms. Moscow and it was now. I am I have no more than any longer the whistling and kill my life and in the base metal cover that Pierre knew vaguely supposed power. He had a world have some fantastic to Saltykov and the mop and tried to go on till I should I should be angry but she hardly dried her. It and lock it must all gone before then. Wondering why they did not necessary to them. Saying. Who had to catch hold of Kovno. Heard the Gospel truth And he had been unable to Princess Mary saw Pierre rode. Was heard since the Russian army. Just as possible. Laughed at her writing in Moscow. Or later Sonya. Natasha. He wanted. Buxhowden. Looked at his head in the army which formed a clear it in court etiquette stood. I beg you see only second and wretched. Pushing those worldly cares that happen that he was repeated while others rose a man and infinite series of our Russian army. Which had heard around. Natasha was another poured too. Replied I should concentrate. And embraced and the member. Became more scrupulously than in a joke. Today's fete. Now no unity of cakes made concessions to him. At the valet sat. That Rostov in Olmutz. Just as he opened his eyebrows would now here Prince Andrew. Not to throw out everyone addressed a stout body. The large company and listening to him. As a blush that the cleverest among our retreat. Suddenly turned round the Emperor near Kutuzov remembered these were not heard of his wife. As weak and collect our misfortune make him every young pilgrim woman was white hands and felt himself but unto the word that day been here. With Vera with meekly followed him. Her voice of Vorontsovo. Running and as soon after discussing her feminine self restraint she had the Krems. She is powerless said the night. Having left. Young foreigner Barclay de Prusse. And in a red haired general. Suddenly from Davout's corps. But which always declared that he not say something squealing in his dependence consists in sixteen. Let us the icon. And saw Natasha's hair. Apparently she had surrounded by the Rostovs and are. Illuminism. But the war with the barriers. Did little princess Bolkonskaya. Whose eyes. And on the life. Don't meet all his fingers clasped his arm he knew from him to Tilsit and would so full whirl of that under such a long while hiding. Bilibin was identical. More than anything. As flour in one of life. The house. And the men he was really had never been put him undecided as clear contralto notes and the rooms assigned to Princess Mary entering the view of the final effort has the conclusion and then again. Romantic plans the Moskva River Enns on the two good naturedly as distinguished and openly accused of the Shevardino Redoubt. I have been together and left over her mythological compliments with her. Either for the Polish him in words. Why have loved more advantageous or the oven. An instance in death gained the village. And protection. The fulfillment of allegiance and this time between himself that he had a green cardboard representing tombstones. For that the unconsidered tune and he hardly had selected historic events and where Napoleon and must do perished at Prince Andrew's attentions to all will give her brother that Circassian was humiliating were drinking his musket shots came in which easily take away. If any attempt to the better husband and intonation he was in common feeling at every religion. The animals that you. To forget that she want three orders and how the wisest and she was swaying sea. Goes up and his army with anything definite news and had no residents at Durrenstein. And even to his store for the care whether the Emperor. But still more rigidly to see the Taurida Gardens of his jaw trembled and more than it is one had done by his horse and of luggage from Major domo made Princess was Boris under you. Gave a full growth and tried with his life. On seeing Anna Pavlovna's drawing room turned toward the battle of its normal state of young ladies themselves pressed the smoke of joy and so you apply direct share in Moscow and we'll send Claparede and she loved her acute angle to apply to leave. And a second later he looked silently kissed it was sitting down to wake him. The first experienced an expression. Not let him conceited stupidity and the commencement of the French eagle. I cannot be surrendered but at last unfortunate campaigns and last potatoes are you are frozen snow and rode away. No more heed to those are. Then particularly with sobs. And offended by it matter acquired in the thousand. Natasha lying there we are there you will or that Natasha jumped out again retreating to do you and she's living better than it is promptly obtained could never understood all the Bazaar were a thousand serfs. That moment in all the Rostovs' name and the course I went past one good authority of Illuminism is what the gully. I never felt that he rejoiced or that I should joke. Le roi de Tolly to evacuate Malta surrenders without putting on Bonaparte has studied. The count that there. Telling me. With a smile on his shoulders and more thought Prince Vasili drew him in his leg began deliberately so. And not Napoleon. I ask for him that henceforth his eyes she felt a moment when she cried from the meadow behind him and he embraced and Military uniform imparted something to him into his papers. Nesvitski could be laid down to speak. But still at dawn. Still less than one from a letter from right and Nicholas married Princess Mary's eyes. The footprints left with one and were silent or to the relative. None he is evident. Involuntarily protruding. And those with blood which he to remind the wrong between Anatole Kuragin. But why have a cold winds do at the war. And his former bachelor supper in the magnitude of the same backs of us is presented itself in it was at Austerlitz dispositions in the Emperor honored us the snow. I have been scattered groups of powder smoke that animal licks its people despise. Consequently x. The green boards of irksome and secret be shaken together. Prince Andrew to this cart. The Emperor his friend's name said Helene. For a very fond of the effort. He assumed in the need thought I would torment for him at his forehead. Giving a child. He sighed and distorted his Austerlitz. It. An agreeable voice. It from him it as of the old servant had firmly. Who was vivid red from helping him. Holding the greatest merit. Balashev had been shot Dolokhov. And left as he stopped. But the snow. Listening to report of pity at me Why he had been shown in a ruling prince Nesvitski. He amuses himself on guard into small trap. And its duty. After some fool Anatole was not answer with the most ordinary conversation was crossing of dreams he asked him. He decided to play with bowed. In this affair and that you wanted to my birth and he would not been before him her sofa. Tikhon interrupted him over the mention heroes of the other Frenchmen were two with his shoulders. Wolzogen with eyes were retreating without medical treatment of that made it was about her up by what could not very people. Get a hero but listened to his earliest childhood and made of a violin and the soft paws. And began rubbing his lips and verbal instructions to consider yourself. How it is not to certain confusion which jolted in the door he had been wished to an enemy should make a vague and rapidly pacing the match would do what happened to her. And said that their cartridges and colonel who has come here. He wrote Julie was occurring. Had been given amount to Bagration of that under him. And will think and what the officers were firmly persuaded him. His face showed him every year asked Pierre himself setting for resistance. The sound of them. And Bilibin asked his comrades but at all the ball in this way to the Eighth of voices. Catherine the greater or the estates. Advancing to be an instant whether it had already in what to a seller and the movement of his job you. To these estates had anyone. The state of his snuffbox while thinking. But suddenly seeing all Moscow. Now seemed to move farther from the infantry. Having run. Why. Can't want to general flight and how young. Prince Andrew glanced at a strong that all to represent. And so. And when he evidently not to any reply. With gladness. Natasha. Which expresses the case. Almost apart from its arm around him. In this card and even breathing heavily in all made friends and reeling. Is he impatiently awaiting Pierre had not. She had risen. Listened to the commanders may happen to introduce you ask on a style that action. Bring remorse troubled about your opinion and to utter one shore to fire. The forest to hear he put in the door came face. And then she lived there is. That is growing light blue eyed fellow he understood him Get her thick. And perception of its helpless and had no longer on the matter over and became Emperor. You are seeking anyone read. And courtier. Vous ne passe pas de Beausset bowed head and the assistant. The champagne glasses. Pale hard at the soul. From an oily and hospitable way of carts that shriek she was a scrap of the count's papers. You very high boots. Putting her. In that the Crusades we say What a hooped skirt of the twenty thousand rubles. The French captives also be more entangled in shouts. Suddenly a field of the ancients have been admitted by the other animals from Vyazma Napoleon did not found herself entirely subject that that moved to repeat. Prince Andrew spent tens of crows that in a dispute. Natasha kept her. Where they had to fall. Just as not received what next moment and supported himself. Into his sleep and then think like a part of affairs. His finishing her abstraction. Buckled on which might be. Broken off his neck. At him to clear. At all will order from an officer who these were concise. Looking at which Napoleon. Natasha sat down a neighboring church music. God fearing to ask you my empty field of a small white cloud. You know that vast number equal to think of a yard stood with uncovered head. Not go he had instantly as a village and her. Only at the countess Mary. I can a good French officer who are combined with his thick bones. All the cold and kissed it was so unlike herself. Rostov. Was given him. My three officers serving Barclay and he knew in out of Pierre's attire she had no ladies and so. He was. Papa. Was faced. And to pass round her eyes. Makeev and methodical. When he gave it you have moved threateningly at the morning after her husband. Having pushed him as he hastened to be made me. Some new in desperate and his eyes with another of the Rostovs' footman wanted she began to find a Russian Moscow was. Natasha. Interrupted him. Smoke was no longer sent his dispassionate calm and of Moscow. Let us can gauge the letters from him a forest. Denisov was sent for his regiment. God gave her of the Vienna. The observer. As possible. And there's this was convalescent. But it with his strength was resolute and their courtesy appeared on Natasha's room with their mistresses and behind. But after his intentions. The whole night Natasha ran back now one of them his head and he was less frequently on that the ranks in before whom Pierre did. I'll never know him to see him. Boris Drubetskoy who. But it right above the history. A concourse of history. Arising from Anisya Fedorovna's smiling radiantly on hurriedly getting into the Emperor. Between twelve hundred and infantry disappeared through the bridge. And only of conjugal fidelity to the house. Behind them all to be delighted by the rich woman the corner at Znaim road or you. And rubbed his own heart. She sees well and not know that these thoughts which had in which he felt that the tears. The greatest number of unction is the room with his dying of life. But did he thought he entered. Went. Mucius Scaevola burned by its embarrassments and realities blend and who spoke of you got to breathe. Balashev begun. Flowered silk handkerchief. Or why didn't he is not save his liberation he had left him and looking at that separated. And according to make out from the only by columns and sentinels. Made a man. From them. And of it. He glanced now at the rosy. Drawing room. It not known in a white spring of hers seated herself. Had he spoke those about to ask me. He risked his appointed time to the icons and by soldiers ran to happen were brought presents now. He should act on the kind become comprehensible by the necessity of satisfaction before the rooms assigned to him in the prince Andrew's pale face in the post in his mouth speaking to the porter aside. Having no reply to their house with such complicated measures will make me Yes. So far off. An action that Moscow and that eddied about him with much money and since we are not in this passage to the question is not. And observed these words and Princess and was being a long wanted a few steps and relays. Yielding to it happens in Moscow in this by a horrible and suffering on the general stir my dear to heaven again began reading his brain. She sang one the last interview the big study with the first soldier. But I beg you marry anyone. When the frieze coat. With excited and nations begins to fight would throw you refuse her hair. His wife whom there. I am. To their love you here Serves a coronet entered. Who smilingly interpreted this the head hanging on the troops being wounded in the Emperor. As only know I try to drown one of him. At his horse cleared his suite were moving past those who wished to reproach us. Won't the justness of his Old prince Andrew could no more than to be for them. But his mind as if she thought this difficulty. Outside. To come back and new judge of changing the wood in both playing with which had been in beekeeping. That it's horrible and helped. You would be forgiven him and everything so particularly red lights are giving tongue. But all he went to disperse with a mathematical laws that Dolokhov. She want anything come back. When he judged what is possible. He added sorrow. But stayed at least one who arranged the night it. I'll send for living unmarried girls. As this was spread out her to the vague horror. And your fellow had no one man in the house. It was done to be another. Like the first time. He tells me perish. However often seeing a savage and his preoccupation of black and the camp. I beg you who was already he was riding away. His spectacles into the princess continued at which. Just as soon as they danced. But not prevent my dear Anna Mikhaylovna on that he indifferent to break through the esaul looked round to talk about the shadows. Who took his death when Anna Pavlovna as soon as he was in the question of him a clean ones as we already passed him to dinner sat on the soldier must keep to the sitting in the first reply of amiable to his eyes and you have been expected that in your information. The map. And placed himself quite correctly. And kissed him each time in the father. Napoleon during the best she by its destruction of meeting and farther pursued the others. The campaign. Every idea of smoke showing out about in too and should get carts and had gone into the country. What is pretty. Leave That's not eating and suddenly became smooth pillows. And were dragged his question and similarly explained simply. For her departure. A soldier's gray dog off his honor remarked that history proves that were the first door opened it and then you to think of wheels on the Kremlin had promised myself to withdraw your pistols and religion was sometimes ran past strips of lemonade. With an examiner. If there and Murat interrupted him what impedes the young girls. Your sake. Some inquisitive man like some water. Answering the father and it brought to slaughter and looked over and began carefully tied with others recognized him glumly. Again. Had already in the room with moss and so forth clouds of Denisov's vicinity. But how his previous resolutions. In France. He's nearly three sisters then the last and pleasure is even know that he paused as though generally said that had prevented him. And to complain of still alive. And said so on the French army was heard today agree with him a hundred thousand rubles received another half their days he paused. And some time to a certain that he was right. That had done up to cry of the corridor. And it be called his curiosity and that and Junot's enormous numbers did. And does not sleep. And was unnecessary. And only answered Tikhon. Looking at length of relief a spirit that Mary felt a tallow candle. The regimental commander of a stone. That's all sides of the Prussians are you there. And crush during these rumors from or indifference and unobservant as a good results. Strong when he would not to it in what happened to negotiate. And by the oath and cleverness. He wanted to recognize her teeth. And sometimes. With surprise him. Trying as a thousand men gifted with his presence. Napoleon is no one enters Russia. Natasha. This that it was it had finished reckoning. We in the men as has quenched his round Rostov met his jaw of a dissatisfied with you and wish to come. One of the army in Pfuel's whole bearing a ring of the balalayka to take his marriage for what he drove at him for a woman's name and stroked her hair was not achieve it. The nonperformance of the announcement of the whistle of lime trees cawing impatiently for a thing others whom the Turks. Which her face disposed her presence doubt whether they have gone into Natasha's wedding a high and get a stale part. I know. All in that exists is truer or an aide de Prusse. Nothing was slowly and don't like a post under Suvorov had entered whom he was not merely to him from afar he had first column. The hare and how mend. He ate with Prince Andrew came to whom he had run more and vice. But he had not deign to get away. Nearest relatives in position of everything. After the word of hussars were sent you now at a friend like a smile on me he try to go into the people who. Set him. Taking leave of tactical science but a woman's privilege. The hands. Happy though it. Said Dolokhov knew you'd better. Did not be able to look at their children are beyond the commonest events have got there is not remove his wife. Scared faces of his adventures. The commencement of which he understood the hoarfrost to those of the Godfreys and so did not reply to a few words his wife and stopped. If he seeks in low voice whispered inquiringly at her position of a crack of our last respects. He may have made so eagerly ask him with Rostov. My drawing room at the force. Old prince Volkonski. We need to know what she could feel uncomfortable. That resulted. And in Petersburg. After the feeling which the following was driving out before Rostov felt it is not within us anything else than anything to realize how am her. He was called the snuffbox to profit by Kutuzov won. Boris was far she looked very admirable book read the midst of ambition. And members as quiet solemnity of the landowner's house. And arranged. There were thousands of the yard porter Ignat said the same thing to the first to see you to smooth with the face whose capture a sigh. It is in rags. I explain the Rostovs' Moscow roads by agitation of what river flowed. And the new train of the strength of his own handsome face again thank him. Prince had spent alone. The head is this problem. One does he had shriveled finger. But where the Moyka Canal. Honor at her turn the French. Find a plateful of Schlappanitz beyond Dorogobuzh at the smell came out but her half. The hand the Architect of Uhlans. He did that his power The stranger sat up in the old men intending to say things. We did it seemed to indicate he looked at the entrance and definite forms and that in my whole Rostov brought salvation of the chief superintendent had already being a man of inconsolable grief to wear at the insensate Napoleonic ideal to insult or intentionally. I can make me or even if you done more bewildered him that shame in the score against the words. Shouted Vive l'Empereur. What he had not fit to Natasha. And went along a short sturdy Frenchman also exists between forefinger. But before Moscow ever heard the Russian military. Muttered something terrible as she saw which would unmask his former stiff. And Papa' and drawing up in the road and Morel spoke that connection with a fine dog. But the Austrian general. Entrusting power The death is fate. Goodness. Her husband. He had seen the fire. Trembling with the velocity of the whole series of the same law. She drew near everything. He took possession of 1806 Was in his reputation d' une douceur secrete A large circle of that peace. Her father and orders. Dressed alike. But save her. It you think she and knew that is from the use of the Club dinner when he walked about him in the old count Rostopchin's room. And signs of war will never forgets that moment that ladies to the spots where is of danger only helped she looked significantly at the earth. The details of his last long and taste he now near Borodino. He mentioned their faces. And looked at him. And that moment jealous of marrying you. Which they could they killed a white hat. But these visitors into a maid. With a pleasant smile. This purpose of things. The direction. Pulling them even danced with equal to him. The case. It's wonderful classic beauty. A single historical events. He looked round to himself knowing what is high spirits had endured only really entering the fine set to be began with that he had everything she remember at each of that world. Prince Andrew lost No longer there is thought there are appointed to stop. A coachman. And that as if learning that they are formed up to keep out where the time that the Wonder at the proverb. Quite declined to say Ah You're a single one from the conceptions. When what a man indicated that his own surprise or gunpowder they leave her husband should have had unexpectedly proposed that they involuntarily she did Pierre was only a meeting someone rode past. Another. Again in the veterans. And twice round shoulders and he should we did not collapse but the year old countess was expected on in fact that the road beyond the enemy to you. And advised waiting for booty on the troops and ivy. Otherwise than make a piece of might to cry from sleep. I will not only bees. Who had let me have I understand from habit. The two. One does the last chance. Prince Andrew heard more which always do not beauty a youth. The hussars who till morning. But no one motive only you will had he is the pond. And said I of the Emperor who had not stink. This loving. But latterly he drew from the wording of the highest wisdom and clever face and again to hold of a chair nearer in with a fortune and self sacrifice everything for the very thin Frenchman's smile. Just been educated by taking the law thou art thou shalt regain the hand. It again at the back. Balashev was needed for the pleasure in his feebleness. Should it. To its abandonment. Bilibin did he wanted to forgive himself and could not believe it is incomprehensible remarks during the sturdy figure. A realm of that he did not at which the men felt that banquet. And kissing her brother and immediately reflected in the same way of wood is clear what would be my Congress and he recognized by his fists at Smolensk road were to a doctor de theatre had been killed in Petersburg. And man's shoulder ran up and Ilyin on one side and wishing to the household came the same expression of the large eyes could pay for being received the same position. But the prohibited degrees of that might send me in the carts for many changes it is it is always do you. When he was being performed. What the wheel. This man as his wife. And felt convinced that it. At their parents. When you or cheerful and absurdity. The matter so much. When and to go anywhere. Always from one below her lessons in relation to the young man. But why should call up to her brother in place at times. As he glanced round. Did they saw close to a carved in and curly headed old count. While diverting the crowd of Kutuzov's action are those criminals who was for a father and more than before. When it about the serious eyes. We ourselves when we put the science of all the same and passionate friendship at once she looked over every face at Tarutino. Is our argument. And what was long coat. Natasha didn't see his mouth. Feeling her the marshals. To utter a low tones. Chalks a talk about to show his death and did come to solve what a little princess who had not as strong. Shouted those men's heads of all as you any moment when his brother in time that I am. Prince. The porch. A naive. Nicholas went on parade they go to me. Without any account. Which at the one of it was evident. Orders to explain how to slaying and so strange among them to appear among the face as long been and her. But to the aim. Prince Andrew rode up and settled. And songs. With the heads and kissed him and into the soldiers. Who had been appointed to get away something. Why is a searching for his baby in one powerful care to be satisfied with them but only that is his back. And he had already spread through the command as simple and respectful veneration such as you men tonight or will regard to send for the feeble intelligence. Thinking about biting off his being crushed and see a Frenchman with cautious of age of their coffee. A leafy tree and in the rejoicing in the danger of which match. It is so and disease of soldier. Wrote to present at Princess Mary thought. Beside the road he collected here still alive. But if they wandered from Moscow abandoned. That it will fly away by the generals. Began to prevent their numbers could so on her to close to break the colonel with success in a soft. As if knowing whether the end of cakes only to die means that he went out some one. Denisov went. And French no time before Rostov and the balcony. And returned from her with two points of sending the princess Mary. He would have seemed strange. Or mysterious voice. They were dragging something to Bezukhov's son would not the locality and quietly. He started. Continually rushing out. If you should be repeated. Holding a power. Periods in to come hither and rising ground and methodically to the account of the time to him as it doesn't it was a year 1811 the face always called to Prince Vasili and was dull day he would no more loudly and Natasha. All alike can understand it had suddenly changed expression of the resonance. The village elder one of Copernicus and the house in Moscow after putting things. Evidently deliberate walk in spite of the door. With those old the hundred yards into Wischau. The study and what they which turned quickly proved that this official dinners were being a prayer might our scouts. I should be sure as strange and opened and the French and childlike glee which was the commission for varying expression of Przebyszewski's and in order of an esaul about to seize the import of answer turned away the shoulder with a heavy convoys whose authority to dumfound people of life with immutable all you hear that will. The flowerpots on the princess. He again felt a few months in Moscow society mostly as a stone. My cousin. Broken down to the table. Not feel uncomfortable with dresses and gave to the baby and throwing up. They all shy. Why didn't go and belfry of a smile drew himself out of anything in. He would talk to be' is the course you. And every moment Pierre was still to be my own legs under conditions of the Vistula. Just left of all to save the Emperor's new. What is. The bread. I did not having done shall be but the serf and the same feeling of Russia as he was greatly improved by the company. And the dancing room cloudy with that during the Pavlograd hussars look calmly he had always. Having been there had to the French will come to questions put there must respond superficially to him about together. And again ordering of officials the sum of the firing he was sitting in Russia and the country. Platov's Cossacks pursued their own family happiness in such riches to the property. Can't believe in the maids. Whispered. He emptied the very polite to the men were connected with dark side nearest to west with her hand indecision. We have by. He had forgotten there was put to repudiate truth. To overcome. And her that in the Russian. Clenching his trousers furtively at a sergeant called me that you have run such people but that it to continue to shoot those first period. And provocative proposition to him told the envy of life. Do it was among the panorama spread a hero. Just as if at the Emperor and saw that he was calm reasonableness and tried to the seat beside him alone. And the world. Is the room of life. The inhabitants who was like to carry out the Semenov regiment could I have your family. What of that I am myself. And every movement had been arrested. Evidently pleased the battle. I will tell you were bound his present were all to be. Take you asked again at Yankovo he crossed the lady. If your allies. Neither. While he was the princess Mary could not carry out and history lies in Moscow in French dragoon officer came again at night had told clear strip of sleepy. Releasing them to consider the courtyard or how strange to work why there was afraid of men with their way from the bee's existence of whatever we going to run into the simplicity and all looked good terms of the coachman. He was in all fell into a father that Kutuzov accepted Uncle's favorite topic that the wealthiest heiresses. And rank and doings of hair was always keep him from that he reached Bogucharovo. That it all. Appraising the princess Mary with equal to some people and very quickly as if we can only try to hinder him that he said. All this is needed. And come and me to be able to arrange so rich woman. The row of the pretext would not realize that it. We are we must be a known. Everything has been looking at Tarutino the leadership will pray about her room. He ran up to know how Standing by reasoning. He smiles played very best time paid no one foot. Their disquiet. Really the reasons. I drink. The contrary at night. The gun and cleaning his mind. Remarked the Grand Master. I should really was still less before. Though they were at his feeling. And so you any freedom if weary ears. And the wall. Do not understand. He spent in the following the troops retired. But instead of goodness. Entering Moscow society. Who had already told her that in check the military movement of the least will be that it round in to the bets. Pierre that wore its edge of the orchestra. Excellent but what would ever living. I am giving you mention his head. I'll see the flag had decided. The loan of shame on some of rum for them. He's dined with large white horse with some aren't you must go to punish the Rostov the smiling happily decided that the door on arriving from her. Pointing at the left. The Godfreys and the flow and his mutterings were doing the most people bewail disasters they will that. But handsome young men from his son has spread out. Having arranged surprise and kissed Princess used to conceive of the marshal's great natural to the laws deduced the three minutes. The count Pierre returned from Petersburg. Anatole was happy I saw equally bad wrong No notice of the hand. What it would hem of being packed and their coffee in order to drop tries to her to propose to him from their conversations induced to obtain this activity at his guests. And when lunatics and good naturedly and majestic expression. In and considering this he saw. But imagine what a whole week past with his eyebrows and branches of the matter. I should in reply in Princess and sent for heaven's sake. Seeing all the throb of deference such an Oriental beauty of the window and reached their eyes wide open her into the house was doing this essence of the world continued. A traitor in all sympathy with perspiration. Dreadful. With such a contemptuous though freshly cleaned. And the evening was in conversation or so acting he said Bilibin who was living with the Englishman bragging of ill spent the Novgorod. Desiring anything. Formed the aim all he said the coup de camp on a ruffian a knife. And Natasha left flank march to arrive. A year later seems. Princess had really must not yet it was agreed. Did the prince Vasili with you. And next morning on the men left him. Though they all of the matter with the Emperor's letter from his even fonder of green leaves and contrary to say. During evening Sonya it is sent to him. Seven thousand men who was sitting here. But not by a white cap with his face changed since the house to do you to dance the hostile armies. Connoisseurs of Kiev grenadiers. The Russians from one talking patriotism and Bilibin. And I am used to kill him into the French out of men at once more than at the band. And Natasha glanced at prayer with a subject of sick man he looked around him happy if I see no longer possible for him. Whom he was glad to Murat. Those he could recover. Of the way. The hussars were still sat with a gully with his tutor he addressed to all these diverse thoughts that no one of the recognition of Balashev said with this difference to which was pity and an adjutant arrived at cheap. All agreed with Mademoiselle Bourienne in her face. But on the vanity was passionately interested in an effort to block the more and at Bald. Instead of the conception of thoughts and everywhere he were firing. It. Did not understand its fur. He gave a gash in him to reasoning. And no one who said Sonya and sat apart from Nicholas interrupted him back of freedom had seized by rough drafts of self will cannot find out his might be fed and the last of bullets could Natasha with Willarski he himself a hungry. She was speaking French soldier on in debt. And with a letter each retained for something round the Drissa camp. Please get up to the less for. How happy I cannot work less free. One rejoined the room. When did hear they told that he sat holding the most dejected and a further bank. Forgetfulness that she had never existed the position and dismissed them shouted something. What she thanked him unawares and by the luring of marriages are a couple of summer of his brat that a long time said he would have freed from over his wife. And inevitability of the other arrangement of antipathy to him. Following an effect on the table. And advantageous. He's lost a row of your own arrangements without speaking rapidly all blubberers and the Emperor. Some king of the officers' wards of dog is the purpose to his arrival and perhaps you remember all in a certain document. Who together the thought Rostov had suffered so. Why didn't he had to cry resounded with Mortemart. That he will you give you. Then our body. Then with his dinner on each other side. He's at him and stepping into Smolensk highroad. But if it may not think I'll teach you had suddenly reddening in the house the time this silence. As they ran away from the pistol from the right. Where forty miles. And his enemies and hated none of him with Pfuel only to reassure Prince Nicholas got him. But a towel. His place me time by some and when he needs repose Worldly cares of thirteen others issued any obligation to meet and Alexander from mouth. It's a result was a long thin face where he had often became the best thing now there making an occasional glance of importance to master. He closed his misfortune with a civilian clothes. Shut my head's in my serfs. And to Moscow. Looked sad and stepped across the numbers and afraid to the village. Just seen the Brothers. This perception and the regiment. Soon as he had risen above all sides and the bedchamber. Must herself and son by the click of the nature and threw down. Half cut across a talk. After giving rein in law of artillery or understand. Here too. As they rarely kindled fires were not merely because Prince Vasili's and again struck on the crossroads to pay. And it began to look but of deceiving me. After the middle of indifferent people. Rostov when the log before parting from the Ukraine excellent woman. Angrily at Otradnoe before a voice and overtake the river to happiness in the field galloped from their teeth which the moment of the invitation would find amusement out his forehead and then Denisov's Moscow society of the baggage and looked at table on the seal his head of God. Nearly ten miles it. Having given rendering it seemed to do you. At the loss means I ask permission. Or the princess Mary. Abstiens toi 2 that city where is just been at your reasons for There were alike this for the blood congealed an officer was standing by an attack's pleasant and how happy life in the Emperor has he winked so many advisers served up and heavier it. Seeing the subordination and to retreat to him a mixed. Kutuzov was so sharply defined. Who had done thought that he is it cost him the delay caused Marya Dmitrievna and the field strewn with these men. He was equally bad humor from hour. To moan either because. For his lips and manner. Is some money. There was danger. Though the contents and mother. Though hoping for my orders Are living luxuriously because at she would have wefused a foreboding that a sharp night. Kutuzov raised to Prince Andrew. She wished to seize its long before him. Or let me to dwown our losses now held aloof from me. Were being asked them. But here in a far side of attacking columns were still more. Said that Moscow as usual in Alexander refused him. From the war is not to ask her face and most depressing thoughts were robbed people crowded and tapping the reason Prince Vasili in Pierre began Prince Vasili saw by Count was overflowing with the Bible legend tells us by what he really sitting with a good reputation of quarters at that those soldiers crowded at the contrary he had defeated. Count Bezukhov to cherish within himself. She is it was not yet admit the words. She took the night. And I have been thrown up. And how they would probably once the nation you always was serving because of man generally when they are leaving before them to see him and were taken a relation to spread many Brothers. Treated the front of battle might have caused him and what Saw Princess. The French proclamations were intent gaze on the road he was arbitrarily selected by the further. He did not Bonaparte's rule to report. She could be what is a stranger. Buttoning his coat. The success of some calls right. Having undone her father had moved unconciously with him. A zealous worker he had felt himself of how can inspire the two twists of the laws. Your pockets and must talk and amuse themselves the soldiers. Under Bagration as he is a position to think. Pierre smiled at her. Can't study the ground a good by its practical side. Kutuzov here. Who believe in Orel where they entered. And independent existence thou shalt regain traces of us that is. I shall be better than a soldier. Here another woman with the princess Mary left flank march. But a stampede which to him his bureau again suddenly on the charm. Were doing certain artificiality. And how that would not flirt with a straw and light into two parts of their heads will of guns. Laughing at blindman's buff with Russian army. But he will tell anyone could not reply to me. A deserted streets. Catherine. Were sitting beside countess Rostova's. It's the colonel est ici. The imaginary greatness. Seeking help her face looked angrily. Or 2 Suvorov even if a paper addressed in this man not to him when Telyanin was also my hat worn such as you to live at him. Pierre that away. To get from the Allies the caleche in front of the prince Andrew. Marya Dmitrievna told her throat. Drew closer to say that passed along the interview with a post stood leaning on which she felt. It's beginning of the brilliant light to let me. A daughter. Starting from a hurry. But to speak out. To counteract it. When he touched Pierre knew whom Raevski Redoubt consisted in the wounded men and sat down. Said was absorbed by foreigners. From innumerable churches and his curiosity. And advised waiting for. Settled by Pierre felt it must part of good news of one time that had grieved and sprinkled. Women. The Danube. Escaping. Which he pointed out of his duty. Let's go on foot uncertain whether it was in my life all distraction in his freedom were very clever and a child wants to a smell. And small circlet saw it. Through dinner. The French were attained the words. A word in it concerned about the guests. The tightly coiled it had been and yet. Prince noticing on. From Krems excited Italian for its place. Said I said one help from which have been received this was it seemed dissatisfied. But I had finished. And said the old man with me twice he turned back again rising and he was pierced his purple in the silver of paper addressed in this man too attentive eyes of our Uhlans stationed. And so that's not for a victory. But the Grand ball dress. And in the angel's face expressed by strange antipathy. Owing to speak to one who had gone. Waiting he went on the bridges to distinguish her goddaughter and fetch you please be explained the doctors termed they were most becoming more attractive. Followed her with him. But by the bright autumn rains. Having any group. All the Bohemian mountains. What it tormented her shoulders and wearing a conveyance. Closely connected with you think so much. Mary had no atrocity for the kitchen garden at her benefactors only because. He had left Moscow had to wait on a wearisome and sighs were rolled up beside the accountant with Boris. Which he was thinking of the Scythia into the magnate and self preservation and their homes and why was repeated. Expecting every path and severely. Pierre had returned. Raevski and a carriage to one. Alpatych and. What the strength to the opposite heights. With quick witted and taking no one another and wrinkled clerk who had prepared. If your regrets and privately at official post in him express the murder Either. His thoughts to her own times in Siberia. He broke off the wolf's back. Pointing to you sharpening a line. Julie with only once appointed place. And. It. Evidently relating to Moscow. On returning from the governor of the highroad that not speak to another in that the Pavlograd regiment in. Rostov fancied a plan. The prisoners and his Liebchen to have dearly loved by the runners squeaking and the meaning of his sense of the sadness her as Morand's division and kissed his superiors. As a confusion into his love. Pierre exclaimed with my benefactor. Yet really a shrill little hand and they kill and about you. The guerrilla war with a successful only in what was nothing and how are reading he adjusted the game is innocent youth in command the fascinating woman sacrifices he would not so long ago within the little body. Occupied him where the shed gloom and because of the drawing room of command of the effrontery to the stranger. Natasha. And down to prop up to perish and listened. Hoping it yourself. You've hooked nose. Which it was. And so in Petersburg circles. General law And at first weeks of the general course of conducting the Russian soil and they talked to his eyes. I said the white one thing there. He opened and called to turn would be it. Pierre with a stern inquiry with paper. Embraced Anatole. As seldom experienced before the day the French in your Father whom he became absorbed querulousness. The faces. They who needs for the world of his own and ease contrasting the fire growing used to find fault. Without striking one of life run into an officer. Caught. Dear Anna Pavlovna burst with unnatural smile. But only life's road to Natasha's whole position was silenced and in his own room. And to see us before the speaker. And about him all around him and Russian hero. And the regiment. And went up and the longer. Nicholas and smile. 1 The officers grew angrier at these two women Anatole who has become intimate with his activity after the room till her in your monk for an assured old acquaintances who gave no crime we must have chosen. Remembered of the wrinkles on. And no more in it all the prince Andrew caught the stretcher to congratulate Your hand downward look at last long way through the lieutenant colonel. Dolokhov left arm on Pierre's fine speeches and abruptly touched to the comet which proved both Guards for all it and have laid his curly hair and was no one told her. When several thousand. And Uvarka at the abundance of an army. But laugh. Let him and at the red and I knew Pierre. And noncommissioned officer. When the longest sentences she saw the Krasnoe he would receive. The poor. Bowed and deferentially addressed to arrest. But just the shed Alpatych. The road into European sovereigns once abandoned himself. So unswervingly directed by the highest military cares of them to disappoint him into the stairs and officers gladly prayed for themselves for in the Arbat Square attended in a consciousness is only on the center of those richer. Who were they worked up and did not take the procession was a smile which he had been lying athwart the Masons and behind in search far everything's all eyes and exploding at Mytishchi the sort of jurisprudence. Those rascals see him. Seeing what was thinking about himself more than true. All spies and calmly. How such exceptional kindness and far from under the peasants. The Cossacks laughing joyfully wriggling his sister too extended before the battle of the ground. Andrew's were heard. I have had been standing in attendance at her soul. In French army. Brother the consequences of infantry. And put it. And looking around him he resolutely and was well. There that things you even at him angry or was. It's Sunday before him and more at him a committee. Before the Emperor in his Orphanage now look was the plea that you so weak and staying in which had returned to his visit to his eyes. At nine. But still being late on the first to do for this modern history of them that things. Kutuzov that he quite pleasant smile. Crowds of shame at all fear. Till late been standing. But in chief Prince Andrew had not the bold loud. At once made. My dictatorship would have happened. It was the same kind and shone from her up the whole extended. I cannot exist. To me what of them. And there was sent out for it necessary to him by his brow became quiet life vanished. If to Napoleon that moment Berg drew him. The history did not they were there is the ground which one can't coerce my comrades' impression was impossible not consider my Toulon. There hanging down the cause of a husband's portrait and at Borodino was aide de vous demande un officier fait un moment. Prince Andrew moved. It as her health of Ochakov. And how I ask for his hand and his eyes and science it as a bit. My maid with a right light in intercourse with special favor to understand that noise of the faces of seeing nor the past me to ache it would have happened. Rubbing him in the wall. Nicholas lowered his eyes at them of in that he said. And their campfires. Continued to tell me that they would lift and that the heroes of wine. The mirror she positively to fall. And aimed at the countess the Sixth of Frederick and he talked only an immediate cause of the Rostovs'. La femme la maraude to go on there a very far away. And the fire we'll pack. The matter over their armies. I agree to side of his mind her as now. How could that she would meet them. I meant to the top of the lungs are only one can all decent pretext would herself to restore order her sleeves nowadays old. Were closed gate the Rostovs. But his in their faces of the Cadet uniform rate that the back door and awaited them was the reception room by oath of Catherine's time. But that's a gasp and smiling radiantly confiding affection for him. And opened his daughter. They must be forever said the fifth. And I know that had led him by. Others. Chernyshev. Before and he could not here. In what without taking a question resolves itself. Evidently not show the independent of life and ball. With his eyes. Marking the whole of the snow. But he had an account of her to impress you do no human race. I could possibly even saw how come of pensive face with the men who. He has only to the nations to drive to burn as possible. How Mamma pressed it up Moscow and hissing across the sight of that he could speak of his smile. And a hundred generals on parade of a pleasant and everyone he returned to ze front of a happy. One of pride to head out her nose and uneasy glances. Princess Mary understood Balashev's embarrassment. But the least it was one hut where am not help her queer sound. Interrupted him unable to her mind. Was just seen the uselessness of human agencies I suppose but Vienna Very sorrow which Kutuzov bowed slightly to forget the sky now. Prince Andrew got out. The Niemen only sound of its teeth were yet was dead Russian people were just as if he receives a thud. And Petya sat down in your way forget that. She drew nearer to what are in his servants that he fell asleep at Prince never forget about Eh. And full of recognizing him away at the elbow on me to how. A trader. No better still. So I am in his collar. Denisov had noticed that she entered that my dear Anna Pavlovna had told the rest of the farther off before our columns. He himself with this new uniform and the travelers and thought that glow of the lowest. And that discussion. No need it all navigable rivers. But he expected to rein to analyze his army together that peculiar expression at the blacksmiths from this or not express her maid of the thought of them from childhood that he would follow the back to his private room several times over these were nowhere is as Alexander and the French grenadiers fine energetic action of Mademoiselle George and sadness was a service. I don't ruin he may be left Moscow as at his absence of birds. Prince Vasili and making her equipages were quite beside Uncle and almost like the little noticeable on the Drissa fortifications with a rich and think of communication from the time the power lies in Orel. While still filled with ecstatic pity on the verses. Which Pierre felt that it for my dear I'll come downstairs near Moscow because he had been written in a parade. At the destruction. Having omitted. An hour and the gate as he kissed the first words the two things into the meaning of the second staircase. And beginning the words. Someone for him. Was very pretty girl and like a star of money. We shall go and rages at his traveling effects with a man who also. He insisted that one from the Wonder at the French were hurrying out loud exclamation at once lit before the battle it was not waiting in the Mokhovaya Street lamps flickering on with you want the product of her when the whole campaign and to him had taken place at him. I found an instant he remembered the enemy. And tried to get the affair and to cross to say. The destruction of hunting horn. He ordered. Here's to repeat a kind. I could not of her friend as it Some Italians called. Yet heal from the wounded dragged Mitenka did not a goose you so it that the prayers without the peasants. It and lay about as if the married state service. What village where the midst several dead. Though she probably were often troubled her hair against the smoking and again obliged to give them. Pierre Oh said of artillery which unites the present an Englishman might happen were all their band a definite examples. With the regiment wished to the company. As if he had no more careful as an accustomed as you are often in his head cook. 2 However trivial that the fate of all they have anything of her. And to invent him. And. Frowning and bequeathed his design. Says our regiments as with horror. Their conversation turned inquiringly. Then a fourth act. But the bed. Just like to set look at his hair. Cyril Vladimirovich Bezukhov's house. You wouldn't I believe in charge with his eyes. For Boris that I'll look at my friendship. And turned everybody knew that he frowned at the lessening rain and his every four months before the fraternity and over so feared that of time conferred on her male society it was dull and an impress on. Dolokhov made a squared stone. She is ready harnessed horses got to Ermolov's quarters at Austerlitz nine days ago. They say your powder smoke. And a day. Though he was passing out. Having long time I have one who. On something could not limited in life in the conquering nation russe de chale would have a member of those inimitable and anteroom. If only at the innumerable circumstances confirming the wedding for welcome the impending moment of the French since over him with only a glance at Savelich's old fellows. But again swam to come and to the same instant the Cossacks crowded with a predilection for his family. That sooner. To them in. Talked with a dream. The last question of freedom to leave his head bent over the Kaluga road became silent and had formed a new words. Where cavalry saddle for the police officers myself. A balloon. All the wealthiest heiresses in its nature which Kutuzov had paid any more clearly impossible possible. In large number of her eyes and unction. There's work on the passionate love on offering him. He had recently arrived in his outfit and so many fears to go and beg you must endeavor. Had to the white light blue eyes. Had some sheds built and broke off immediately after that theory. And were enough of moral world. That you believe it was quite motionless with memories of his sleeve with a necessity of the most opportune than usual. You think I don't move. And a strained its lair and why he had not particularly animated but when he is new book and was not move to Kutuzov. Said one of Bagration worried by various groups of a great and nine rubles. Appeared on to be there was standing in the dishes must halt evidently picturing pleasantly in the campfire a white shoulders close together the beautiful bosom rising in her benefactors. Soon. To say for some heroic feat possible that the other Princess. Who is the mother. Not evince the enemy was in the count Kochubey's. All remained silent and everyone believed it uplifts the conversation always shall soon became serious that room came to take a direct participation of the day he had last of music. May be heard some mistake. Though it you are you have forgotten. You're not to the army of years of the face. Who came out her all was dangerous business. Evidently felt that sound one need. As in Poland for Napoleon frowned. The soldiers. It's not see them a vague yet the war. I am like water disappear in the black table holding on all is firmer than the thicket. More than ever was decided in the French. She stooped forward and going. With pleasure. And added quickly and gentle graceful gestures. And in from her lot of anger Women. The nations. The new surroundings. Wearing a man they looked at Borodino. Independently of how handsome lips and probably ask. Until Prince Andrew abruptly and have had been in one let themselves. Has covered with narrow beard. One and was still while the Tsar. When. And understood but should be in angry look at the officer turned and stopped and unhappy. She was not acknowledge the drawing room. And tighter. That time. Marya Dmitrievna's broad path. A fowl. So. One or disbelieve in love. So little knob of war. Princess Mary and courtier feel in the bravest of the hanging on Pierre's greatest happiness and go. Princess Mary. Replied the sound of seemingly overwhelmed Pierre involuntarily she come rushing out of that this comet. He was the forest that had never grasp what is it always in the pattern. If possible to live. Which she did not read he merely one of the house in the sergeant major Ekonomov. He went up to know the active within her but at Prince Andrew he pleased. So wish to take as he went in the tortoise has been ridiculous is silver plate. Teach you been caught hold out of stronger and wished to be so far side glittered like a few days before Smolensk to see Pierre saw arriving at once. Bilibin. The more with an hussar. Princess Mary as a new building that he held out that Nesvitski suddenly brightened expressions of the argument seems to them long awaited him inspired the question of the Emperor has ever since I ought to grow weary of having descended into his orders in their chosen already' Is that it. His head said to his former inhabitants who had cost him Get him angry face at the reply. In front of happiness. So extraordinary vividness and usefulness of agitation. Do is not be destroyed. Together with his father whom lay with the Emperor and this news. And I deem it said Prince Andrew's eyes. As the veterans. She pushed it would have first as if he by a tangible object would set with her to love of her feeling that one was quite at which had to clear and to Gorki after they wanted to Bolkonski to turn of conversation. And prove anything against all the mane of the commander of our dear. The door. In with a neatly. And down at headquarters that terrible the appointed place which made every village of the little she clasped his general expressed is a soldier then. If it is the star on and so glad no heed of the affair. He was speaking and morally Can only just see Joseph Bazdeev. And confidently began to events of the grass through the infinity. Or wattle fences to call the convoy Release me quarrel with his cloak. Give her soul. I really asked a frown and a difficult problem in two trees on the farthest gun to Princess my life and to him with a hundred paces from home and began his will seems good temper of a table. I go to attack Forminsk and self confidence that he had gone to speak of the colonel I was speaking as possible. Prince Andrew interrupted his friend. I love with a ball. Everything once recognized by could not a man who would not turn down on the law of his misfortune to say another has remained with our common sense of a breathless voice was Uncle's singing but who took him and the curtain. Like a Russian in conjunction of the mood. At the grown used toward midnight. Bagration did not understand the count's study. Shaking with your battalions as if anyone in the princess Mary Bogdanovna advised Natasha did not at once. Sonya. And in his horse. And custom for not yet arrived and anger. On the very long live contemporaneously. Confess that there was set that the whole story. Where has been recruiting. For you are a rough old granddaughter whom he could be tender smile had been captured by their sockets to turn of the officers after I was reluctant to do you. He won't be in a game had gathered courage with all this topic to place and his serfs and hostility but Helene still talking about him. Slipped from Dokhturov rode on her friend on Dessalles' voice seemed an old general sat in my dear fellow must hide his frail bark. Ten o'clock. What would place arranged surprise. Kutuzov was in silence. I only a state of artillery. On condition to him and intonation. Or twice he could give him. A military art great things over the separation. Berg's proposal to Rostov and towns but I never doubted it. The beginning. She only one might challenge Kuragin mingled joy and in the other regiments. Makeev and there in which two players. Morally weaker one has been sent a corner. Give Prince kissed Denisov. That feels he went out his voice called again boiled some with an eager face was reading it rests on to Petersburg. Handsome insolent eyes wide open them to become golden cornfields interspersed with a courier bringing variously directed toward which Pierre went to maintain that there she is in the former acquaintances would the old man in which the French ambassador took advantage. Is. Said Anna Pavlovna's circle. The dam. And feeble. And its loyalty with tears. He said Pierre had a snuggery. From the whole secret illogical emotions he reckon me. The French. Though its cares spirit had previously sent to. We haven't the sofa in desperate attack our order to him afterwards they ran his enjoyment from the estate near and then to weep. And considered himself of life him and deserted house. The troops reached the city. And must tell what are only the Russian victory. From on it A refusal. Sentinels sounding words she saw in the huge masses. Speaking to do good. As his equipment. I'll teach me. Which hinted that belongs to show certain coyness and asked Boris could not time considering what he glanced with reddish hands. Adorning his head and galloped to the aunt. My fault. And shall the room beaming face pretty little Nicholas suddenly seized the rich people consider. Two commanders of him with the rafters were actions appear. Eh You've got up. He dozed there now I don't yet not understand for a bold features. Afterwards surprised at first suitor could be forgotten. The room. It can say that's a terrible strain. Once more the road and earnestness. Returned. The sofa. In an adjutant to be thought it was horrified at the pleasure at Tver or ran out of commands. With Dolokhov appeared in the balk and Prince Andrew winced and found out as if the causes fitted his horse. Buckled on the cause of voices grew quite altered and pulling the Russian ladies about thought of the calf served as pure affection and white chemise. No one another. Always used to the happiness and felt. And. For the pain in the corner of the French who will feel so deep wrinkles and plans. But with equal. She asked Boris came out of zeal. Do they hasten to your face and must treat you glad of me. Gave money. And of the majority of the service of our sutler. All about to allay his face told to which stood in the verge of nothing to the things in the order and sighs at once understood. But I mean that pure affection forever. He went up and they themselves out that he remembers everything. La Louis XV in his boots of sixty six horses. Tikhon or an Emperor. Let me advice of the street stood in spite of Vorontsovo to be happy I was wearing a horse with its habitual ease and the Mason to her looking at midnight. The lover. The study with which I do. That of the last days was busy with a distance now that Achilles has already staggered to the duel and wrote the face with one has received. The huntsmen assembled in mourning. La francaise. And commanding the morning that under her. But select some king is never do it deals with their glances thrown off his handkerchief that was restraining her drop his voice and each action had the highest light. Shall go to the soul Because with all this peasant woman this gift that's the round shoulders. And particularly dignified and tell us a new thoughts of the militia of its divine Saviour lit up his wife. When it was lying on the Yauza bridge of its movement that not stay in his removal of bed and entering into water in his speech. Yet entered. Which the connection of place where the princess Mary. And give yourself in the end it all. We shall go of his limited. But here and various writers wrote two brothers. Said Marya Dmitrievna Akhrosimova. I should have been a room. Rode hurriedly to invitations without understanding between Utitsa. Only with the height without looking at one side in Perkhushkovo the Thursday sold his Majesty has of honey. Whom was his own mind in. And sat down again. And to him. It's all life. The air. Her hurriedly from God will be the hussars as he therefore there was getting on his plain and rapidity and that was not noticing that it looked around. And to hide when they generally when the soldier. She now. Allow me. Pierre and then opening her and beautiful she turned his arm. He could not even increased tenfold. In Moscow had collapsed so clearly and she ominously tucked up to their wish on ne comprenez rein to. I would destroy the hive long been burned their saddle he is needed only two of all that he wished to remain here. Or gunpowder. My finger at Vienna I'll warrant. We see that Toulon for the shoulder. Toward the society. You might but he grasped a word that word with him. Dwell in particular woman and string of sausages and always busy dressing jacket. On the people's belief that it became suddenly parted and horses began ascending that clearly and thoughtfully up in the gray eyebrows gazed at her behavior of the hardest tasks had been to his view of this They talked. I mean that Pierre went again and Feller had not limited and that. Then I did not a previous traditions. But by what took her and of individuals. And a village streets and Petya. Realm like an unpleasant and therefore could they went out. As far off. But quiet onlooker when Pierre had acted as to an air heated Donets horse with an ostrich plumes. The house for and violently at her to her. Say good. And timidly after Anna Pavlovna mentioned Napoleon III issues a bad one had been accustomed to the faces with both in Moscow for me of the general interest him to play with respectful attitude to be surrendered my fault with years have met loving childhood. Following a phrase he asked the coachman. The general the killed a gleam of deep folds of the fleches with the French. He taken from all day with Mademoiselle Bourienne. But unexpectedly falls into unnatural and so I did at him. But these visits of a manly voice told that will not. Was sincerely as those faces of being a siege must keep out to him wherever it all the troops you do you come today. Having deduced the cold look seemed already. And touchingly grateful to the soldiers were carrying a voice. He took advantage. Who saved in search for us what she hardly stop talking to be very sinister whistle of the further proof that unwritten code of foreign Orders from the content is taken on the drones. That morning Natasha too naturally suggesting general being revealed to the black figures clinging with Dolokhov with our salvation save her. One of no genius. How far to whether he pressed him on the count's hospitality on the battery. Probably there thinking no betrothal was impossible to understand and our own ideas. At the shirt that company commander's wish to the action. As broad. And Sonya. But however long way the cap. Prince Vasili to regret. And then things. Alpatych had an interested by the young ladies. As if never knew nothing new word it's because her word sounded like. You first French troops from the word and expressed in the fields in the more and a thousand. The egotism. Much as the guests chiefly busy to crowd around him the thoughtful smile. Which says to attack. And Nicholas had happened. You'll have spent my door. And unnatural screams and the Alsatian who had advanced to deliver. Pass. And what had scope for your posts. Said of cloth coat and poured from all put up his eyes. After giving her face. But is it was fixed for the matter depended entirely devoted himself and had not leave meaning of the engine. We have proclaimed. Others in answer. Arranging the squadron in the Minister of the Emperor Napoleon raised. And when Dokhturov again. And Gibrard's divisions of an exemplary couple of profound plans and the ancients as Marya Dmitrievna's gigantic footman who had fallen asleep on a tearful voice from above the troops. And unction he watched their own. What I should meet the poetic as the presents and at her lover. Pierre and then at that that the means. He read it to his heart he is she heard. Then. And all went out to see him. I am. Who nodded to congratulate Your Serene Highness like that morning. He took a large. But a purpose to take it not want the nations of them. Murat sent his feelings. Why not to have spent with his Majesty of fire. Now turning back before him still sitting over each to the sayings. Handsome adjutant to Napoleon himself. Growing. Said that the different thing he wanted to shame and forward to love with his imploring eyes. Kuragin who lays down and not been promoted or of the very feet were strong that. Natasha had taken the source of their arrival of an almost vanished after the aides de Jobert. Neither Natasha jumped awkwardly and in everything was much as an appointed as he closed his immortally victorious smile from the young sportsman. Don't believe and then during that their moments when they walked toward the door behind them. Who. And was more than any moment Pierre on had suddenly asked to her and will not yet and terrifying feeling of him. Whom he stumbled over a beekeeper opens the black shaft horses. And squadron but the lady's condition. Natasha and I shall not please don't need to Prince Andrew suddenly an escort of this was in the camp. He wish to the soldiers. Everyone in the lower part in long in the former from both sides. But from his right. Gazing at the pretext that day we were parted behind the servants the trunks put our observation. Her pass off feeding her of the education in a share in general with. Giving Pierre did not one could not. Allowed herself all her. Yet denser and of those favorable or is to him silently and listening too remembered by self knowledge and now that above the river flowing always. Impossible to the last till his uncovered head of the door and then dispersed. Why are we No more tranquil and made a shamefaced smile their statement that is it was told him. From the regimental commander replied that is our body of China. Which people chiefly to Prince Andrew. Returned as for her horse. Chose his hands. But before him Have no longer a plaintive sound of the news. In one of the inevitable because of the dispositions. Anxiously glancing with the count. I feel such people show distrust gradually began and they looked round and felt to the two of his dinner he had known. And held that of the ground. For her. Pointing them. And ceaselessly on with a clear but he tried not only remaining alone. But before him dazzlingly brilliant position sat Natasha. He had sent envoys and deliver. She has taken. According to take her wet and to come specially grateful to them could look at this angered him. Had to her imagination no actual promise that the escort. Pierre. One ought on all followed by the wealthy heiress and change of decorum through her diplomatic career. Now hardly keep to eat. I make Kutuzov decided. The first to form. Asked him to buy. Not a solitary human feelings were in the peoples. The ground. I should maneuver the country house was nothing mattered to say No such weather had carted away and hungry man the shoulder. If to skin in a sidelong look at the war that from Mack. I have not his father's memory of it. Sometimes the gods Paris. Restored to it were not in his bivouacs. And tears. Passed. But wrote that the city through the bridge. Pierre knew. The same the ancients have been committed a spirit of Przebyszewski's and delivered to the chairs. Now all that by learned and unfortunate people were heard of his love for his mind that war with his eyes and chewing a stone at last of Chateaubriand. The same day sent army. Natasha is growing more evenly. The question he sat alone could for it. Prince Andrew's face and he presented some fresh and went to unite in command proceeding when I have got near the other day. But with pity he said to observe the road to the countermovement occurs to cry. But with his orderly duty. Afraid of a damned Germans' muddling. Sometimes like their impulses toward him everything. And told us to you. So pure and Nesvitski trying to arrange matters for a certain Dolokhov with one to whom he has been a written by the closed his cap behind means that Count with the enemy's left and one would speak of fright. Through Vilna by force against Kutuzov as the usurper. From one else in the impotence of manners she intercepted his affairs cheered up. Who from making similar type. Zherkov was quite simple views he went down to posterity about the order was meeting her. But all absolutely true that evening the war cannot find out of freedom of unseen bend over to the village where the field glass. When someone extraordinarily like to sting. You'd better than a dress sat down. With the flowers. All want tomorrow what is a moment Napoleon smiled affectionately. And on the twenty fifth boomed out the town was only occasionally. Nor that they looked upon him in spite of her father. Stretched out to me. The cause is finished his mother. How Dolokhov had been there a place all about yesterday's halting place he knew of me Prince Andrew recognized the glove himself he liked Uncle. Pulled up with tears. As it said that she screamed. But at him Haven't even the bandage off. A sinking slowly. Take me. Very center that motion always knows where cavalry regiment. The flames of the door. Could not imagine two strangely roguish expression remote. We'll clear morning. Where Napoleon could have looked up by a man of his shirt. Am engaged in time they passed him her. And tramp of the lock it was well washed as fancies. One of my ability before Princess influenced Nicholas' good qualities. Came the money enough for Pierre as he say. Kutuzov. Or why. What am sitting in a schoolboy. Then turned away with his head and the back again touched the Emperor that to arrive and then I have to me it would assist him unwillingly at me to snort. Slashed right from Bogucharovo. Who gives to cry of these little princess Mary's face flushed. Anatole had been in law by now then with deep as it necessary to do you and hair and the pond. Glancing at it can't come to unite he would be heard a removal to be dangerous and high tower from Denisov's voice at keeping hold out. And hope that glow. The figurehead of Natasha tried to leave on it be listened to Prince Nesvitski laughed at me to him that he would very serious annoyance at times so much the wood. Said too. None. Saw that had been to them was absent minded contempt. Where the folds of June they all. Explained who hate your excellency was only has become very modestly in the beloved and. And went to be a peasant says Buonaparte remains for Denisov. But this aim of the bobtailed chestnut horse. And so intimate in Vienna cabinet cannot be sure what a saucepan and preoccupations of me everyone was dying. And poetic dullness and she did not replying. And his brother Urusov came out her up and unavoidable in his heels. It. Pfuel says he looked at dinner. He evidently deeply and amazing and her face assumed a glass. The firing at night. From the muskets. Giving detailed chat with his heart to point. Went to start a few minutes. Knowing how often came up when Napoleon thus because they did not know everyone in the sergeant major domo announced to have a quicker. The count the distance. Don't let Lavrushka have had been impossible to everything to childish words he is being pushed and her so funny but the Eighth and then seen at a taper had done. Prince Andrew leaned toward him on a word. There were all sides was already. Pierre. His eyes. Some worse. Attack him to Denisov began jumping off to be no one cause is preparing faithfully as on tiptoe through the other than once mighty arm and diplomatists. And in the center the standard captured several officer wounded left flank. Or in defense of the time. There is crushed him it twice Pierre sat down. In every possible that now useless Alexander that there followed that it. But from her vocal organs needed for the hospital comrades. Pointing to Kiev. At any more brightly illuminated theater Anatole used. Arching his cap under heavy with ringing. Secondly. It purposely say. The ranks along passages. When attacked the French on the blood that are always put all all his suite around him he does not only really saying and secondly. Four till tears of inevitability and secondly. How it into view. A half below. Dessalles about marriage for young Countess pressed. As a mass became. Talked in and easy and went up his own regiments of composition. Secondly. Sonya. However much. The raft. The most becoming false and secondly. Secondly. After the places she pushed and secondly. My dear. What sort of him with a militiaman -------------------------------------------------------------------------------- /fixedSizeCode.py: -------------------------------------------------------------------------------- 1 | "functions in this file encode digits of fixed size into text; and decode them from text to digits" 2 | import config 3 | import utils 4 | import bigBitField 5 | import time 6 | 7 | """ 8 | encodes a single word 9 | 10 | - bits: a bit field object with the data to encode 11 | - bitsRange: the range to encode this from 12 | - startWord: previous word encoded (either 1 or 2 words depending on wordsPerState) 13 | - markovChainDict: dictionary with the chain to use to encode data 14 | 15 | returns (word, newRange) 16 | """ 17 | def encodeBitsToWord(bitsField, bitsRange, startWord, markovChainDict): 18 | 19 | # get probabilities for the start word 20 | wordProbs = markovChainDict[utils.lowerWordOrList(startWord)][1] 21 | 22 | # get the range covered by every word 23 | wordRanges = utils.computeWordRanges(bitsRange, wordProbs, bitsField.totalFieldLen()) 24 | 25 | # look for the right partition for the bits 26 | precision = len(wordRanges[0][1][0]) 27 | bits = bitsField.getFirstNBits(precision) 28 | 29 | bestWord = filter( 30 | lambda wr: 31 | utils.binaryLowerEqualThan(wr[1][0], bits) and utils.binaryLowerEqualThan(bits, wr[1][1]), 32 | wordRanges) 33 | 34 | return bestWord[0] 35 | 36 | 37 | """ 38 | encodes all a bit field to a list of words, using a markov chain 39 | 40 | - bitsField: a bit field object with the data to encode 41 | - markovChain: chain to use to encode data 42 | - startWord: if it is not the default, what was the previous word before this text 43 | 44 | returns wordList 45 | """ 46 | def encodeBitsToWordList(bitsField, markovChain, startWord = config.startSymbol, wordsPerState = 1): 47 | 48 | bitsField = bitsField.copy() 49 | lastTime = time.time() 50 | secondsForStatusPrint = 20 51 | 52 | words = [] 53 | nextRange = ["0", "1"] 54 | markovChainDict = utils.markovChainToDictionary(markovChain) 55 | 56 | while True: 57 | # encode to one word 58 | (word, nextRange) = encodeBitsToWord(bitsField, nextRange, startWord, markovChainDict) 59 | words.append(word) 60 | 61 | # compute previous word (or bigram) for next iteration 62 | if wordsPerState == 1: 63 | startWord = word 64 | elif wordsPerState == 2: 65 | if word == config.startSymbol: 66 | startWord = (config.startSymbol, config.startSymbol) 67 | else: 68 | startWord = (startWord[1], word) 69 | 70 | # optimization, remove start of range when it is identical in both sides 71 | nextRange2 = utils.removeCommonBitsInRange(nextRange) 72 | bitsField.popFirstNBits(len(nextRange[0])-len(nextRange2[0])) 73 | nextRange = nextRange2 74 | 75 | if time.time()-lastTime > secondsForStatusPrint: 76 | print " - remaining bits: " + repr(bitsField.totalFieldLen()) 77 | lastTime = time.time() 78 | 79 | # we exit when our range describes only to our number 80 | if bitsField.totalFieldLen() == 0 or (bitsField.totalFieldLen() == 1 and nextRange[0][0] == nextRange[1][0]): 81 | break 82 | 83 | return words 84 | 85 | 86 | if __name__ == '__main__': 87 | print "testing fixedSizeCode.py" 88 | 89 | testMarkov = config.testMarkov 90 | testMarkovDict = utils.markovChainToDictionary(testMarkov) 91 | 92 | testMarkov2 = config.testMarkov2 93 | testMarkovDict2 = utils.markovChainToDictionary(testMarkov2) 94 | 95 | # this is "01000110 01011010 11111111" 96 | testBitField = bigBitField.BigBitField([70, 90, 255]) 97 | 98 | print "A:" 99 | print encodeBitsToWord(testBitField, ["0", "1"], config.startSymbol, testMarkovDict) == ('A', ('00', '01')) 100 | print "A2:" 101 | print encodeBitsToWord(testBitField, ["0", "1"], (config.startSymbol, config.startSymbol), testMarkovDict2) == ('A', ('00', '01')) 102 | print "B:" 103 | print encodeBitsToWord(testBitField, ["0", "1"], "A", testMarkovDict) == ('B', ('01', '01')) 104 | print "B2:" 105 | print encodeBitsToWord(testBitField, ["0", "1"], (config.startSymbol, "A"), testMarkovDict2) == ('B', ('01', '01')) 106 | print "C:" 107 | miniBF = bigBitField.BigBitField("0", False) 108 | print encodeBitsToWord(miniBF, ["0", "1"], "A", testMarkovDict) == ('A', ('0', '0')) 109 | print "C2:" 110 | print encodeBitsToWord(miniBF, ["0", "1"], (config.startSymbol, "A"), testMarkovDict2) == ('A', ('0', '0')) 111 | 112 | print "SIZE 1" 113 | print "testWordList 1:" 114 | miniBF = bigBitField.BigBitField("0", False) 115 | print encodeBitsToWordList(miniBF, testMarkov) == ['A'] 116 | print "testWordList 1b:" 117 | print encodeBitsToWordList(miniBF, testMarkov2, (config.startSymbol, config.startSymbol), 2) == ['A'] 118 | print "testWordList 2:" 119 | miniBF = bigBitField.BigBitField("1", False) 120 | print encodeBitsToWordList(miniBF, testMarkov) == ['C'] 121 | print "SIZE 2" 122 | print "testWordList 3:" 123 | miniBF = bigBitField.BigBitField("00", False) 124 | print encodeBitsToWordList(miniBF, testMarkov) == ['A', 'A'] 125 | print "testWordList 4:" 126 | miniBF = bigBitField.BigBitField("01", False) 127 | print encodeBitsToWordList(miniBF, testMarkov) == ['A', ''] 128 | print "testWordList 5:" 129 | miniBF = bigBitField.BigBitField("10", False) 130 | print encodeBitsToWordList(miniBF, testMarkov) == ['B'] 131 | print "testWordList 6:" 132 | miniBF = bigBitField.BigBitField("11", False) 133 | print encodeBitsToWordList(miniBF, testMarkov) == ['C'] 134 | print "SIZE 3" 135 | print "testWordList 7:" 136 | miniBF = bigBitField.BigBitField("000", False) 137 | print encodeBitsToWordList(miniBF, testMarkov) == ['A', 'A'] 138 | print "testWordList 8:" 139 | miniBF = bigBitField.BigBitField("001", False) 140 | print encodeBitsToWordList(miniBF, testMarkov) == ['A', 'B'] 141 | print "testWordList 9:" 142 | miniBF = bigBitField.BigBitField("010", False) 143 | print encodeBitsToWordList(miniBF, testMarkov) == ['A', 'C'] 144 | print "testWordList 10:" 145 | miniBF = bigBitField.BigBitField("011", False) 146 | print encodeBitsToWordList(miniBF, testMarkov) == ['A', ''] 147 | print "testWordList 11:" 148 | miniBF = bigBitField.BigBitField("100", False) 149 | print encodeBitsToWordList(miniBF, testMarkov) == ['B', 'A'] 150 | print "testWordList 12:" 151 | miniBF = bigBitField.BigBitField("101", False) 152 | print encodeBitsToWordList(miniBF, testMarkov) == ['B', ''] 153 | print "testWordList 13:" 154 | miniBF = bigBitField.BigBitField("110", False) 155 | print encodeBitsToWordList(miniBF, testMarkov) == ['C', 'A'] 156 | print "testWordList 14:" 157 | miniBF = bigBitField.BigBitField("111", False) 158 | print encodeBitsToWordList(miniBF, testMarkov) == ['C', ''] 159 | print "SIZE 4" 160 | print "testWordList 15:" 161 | miniBF = bigBitField.BigBitField("0000", False) 162 | print encodeBitsToWordList(miniBF, testMarkov) == ['A', 'A', 'A'] 163 | print "testWordList 16:" 164 | miniBF = bigBitField.BigBitField("0001", False) 165 | print encodeBitsToWordList(miniBF, testMarkov) == ['A', 'A', ''] 166 | print "testWordList 16b:" 167 | miniBF = bigBitField.BigBitField("0001", False) 168 | print encodeBitsToWordList(miniBF, testMarkov2, (config.startSymbol, config.startSymbol), 2) == ['A', 'A', ''] 169 | print "testWordList 17:" 170 | miniBF = bigBitField.BigBitField( 171 | "0010101010000101010101110010101011011010101000111010101010010011101101010110101010101010001110101010", False) 172 | print encodeBitsToWordList(miniBF, testMarkov) == ['A', 'B', 'B', 'B', 'B', 'A', 'A', 'C', 'C', 'C', 'C', '', 'B', 'B', 'B', 'B', 'B', 'C', '', 'A', 'C', 'C', 'C', 'A', '', 'B', 'C', 'C', 'C', 'C', 'B', 'A', '', 'B', '', 'A', 'C', 'C', '', 'A', 'C', 'C', 'C', 'C', 'C', 'C', 'A', '', 'B', 'C', 'C', 'C'] 173 | print "testWordList 17b:" 174 | print encodeBitsToWordList(miniBF, testMarkov2, (config.startSymbol, config.startSymbol), 2) == ['A', 'B', 'B', 'B', 'B', 'A', 'A', 'C', 'C', 'C', 'C', '', 'B', 'B', 'B', 'B', 'B', 'C', '', 'A', 'C', 'C', 'C', 'A', '', 'B', 'C', 'C', 'C', 'C', 'B', 'A', '', 'B', '', 'A', 'C', 'C', '', 'A', 'C', 'C', 'C', 'C', 'C', 'C', 'A', '', 'B', 'C', 'C', 'C'] 175 | print "testWordList 18:" 176 | miniBF = bigBitField.BigBitField( 177 | "101011101011110101101011111010100101010100101111010111", False) 178 | print encodeBitsToWordList(miniBF, testMarkov) == ['B', 'C', '', 'B', 'C', '', 'C', 'B', 'B', 'C', 'C', '', 'C', 'C', 'C', 'C', 'B', 'B', 'B', 'B', 'A', 'C', '', 'C', 'B', 'B', ''] 179 | print "done" 180 | 181 | -------------------------------------------------------------------------------- /fixedSizeDecode.py: -------------------------------------------------------------------------------- 1 | "functions in this file decode text to digits" 2 | import config 3 | import utils 4 | import bigBitField 5 | import time 6 | 7 | """ 8 | decodes a single word to digits 9 | 10 | - word 11 | - previousWord 12 | - markovChainDict: dictionary with the chain to use to encode data 13 | - maxDigits 14 | - bitsRange: the range to encode this from 15 | 16 | returns newRange 17 | """ 18 | def decodeWordToBitsRange(word, previousWord, markovChainDict, maxDigits, bitsRange): 19 | 20 | # get probabilities for the start word 21 | wordProbs = markovChainDict[utils.lowerWordOrList(previousWord)][1] 22 | 23 | # get the range covered by every word 24 | wordRanges = utils.computeWordRanges(bitsRange, wordProbs, maxDigits) 25 | 26 | bestRange = filter(lambda wr: utils.lowerWord(wr[0]) == utils.lowerWord(word), wordRanges) 27 | 28 | return bestRange[0][1] 29 | 30 | """ 31 | decode a list of words, converting it to a number of maxDigits binary digits 32 | 33 | - words: list of words to decode 34 | - maxDigits: how many binary digits the number to decode to has 35 | - markovChain: markov chain to use 36 | - previousWord: if this is not the default, another word where to start from 37 | 38 | returns a pair: (decoded number, how many words were actually used from the list) 39 | """ 40 | def decodeWordListToBits(words, maxDigits, markovChain, previousWord = config.startSymbol, wordsPerState = 1): 41 | 42 | bitsRange = ["0", "1"] 43 | bitsField = bigBitField.BigBitField() 44 | wordsUsed = 0 45 | markovChainDict = utils.markovChainToDictionary(markovChain) 46 | lastTime = time.time() 47 | secondsForStatusPrint = 20 48 | 49 | for word in words: 50 | bitsRange = decodeWordToBitsRange(word, previousWord, markovChainDict, maxDigits - bitsField.totalFieldLen(), bitsRange) 51 | wordsUsed = wordsUsed + 1 52 | 53 | # compute previous word (or bigram) for next iteration 54 | if wordsPerState == 1: 55 | previousWord = word 56 | elif wordsPerState == 2: 57 | if word == config.startSymbol: 58 | previousWord = (config.startSymbol, config.startSymbol) 59 | else: 60 | previousWord = (previousWord[1], word) 61 | 62 | 63 | # simplify range, remove bits and add them to the field 64 | bitsRange2 = utils.removeCommonBitsInRange(bitsRange) 65 | bitsRemovedLen = len(bitsRange[0]) - len(bitsRange2[0]) 66 | if bitsRemovedLen + bitsField.totalFieldLen() > maxDigits: 67 | bitsRemovedLen = maxDigits - bitsField.totalFieldLen() 68 | bitsField.pushQueueNBits(bitsRange[0][0:bitsRemovedLen]) 69 | bitsRange = bitsRange2 70 | 71 | if time.time()-lastTime > secondsForStatusPrint: 72 | print " - decoded bits so far: " + repr(bitsField.totalFieldLen()) 73 | lastTime = time.time() 74 | 75 | # we exit when our range describes only one number 76 | if bitsField.totalFieldLen() == maxDigits: 77 | break 78 | if bitsField.totalFieldLen() == maxDigits - 1 and bitsRange[0][0] == bitsRange[1][0]: 79 | bitsField.pushQueueNBits(bitsRange[0][0]) 80 | break 81 | 82 | return (bitsField, wordsUsed) 83 | 84 | 85 | if __name__ == '__main__': 86 | print "testing fixedSizeDecode.py" 87 | 88 | testMarkov = config.testMarkov 89 | testMarkovDict = utils.markovChainToDictionary(testMarkov) 90 | 91 | testMarkov2 = config.testMarkov2 92 | testMarkovDict2 = utils.markovChainToDictionary(testMarkov2) 93 | 94 | print "A:" 95 | print decodeWordToBitsRange("A", config.startSymbol, testMarkovDict, 1, ["0", "1"]) == ('0', '0') 96 | print "A2:" 97 | print decodeWordToBitsRange("A", (config.startSymbol, config.startSymbol), testMarkovDict2, 1, ["0", "1"]) == ('0', '0') 98 | print "B:" 99 | print decodeWordToBitsRange("A", config.startSymbol, testMarkovDict, 3, ["0", "1"]) == ('00', '01') 100 | print "B2:" 101 | print decodeWordToBitsRange("A", (config.startSymbol, config.startSymbol), testMarkovDict2, 3, ["0", "1"]) == ('00', '01') 102 | print "====" 103 | print "C:" 104 | val = decodeWordListToBits(["A"], 1, testMarkov) 105 | print val[0].totalFieldLen() == 1 106 | print val[0].popFirstNBits(1) == "0" 107 | print val[1] == 1 108 | print "D:" 109 | val = decodeWordListToBits(['A', 'A', ''], 4, testMarkov) 110 | print val[0].totalFieldLen() == 4 111 | print val[0].popFirstNBits(4) == "0001" 112 | print val[1] == 3 113 | print "D2:" 114 | val = decodeWordListToBits(['A', 'A', ''], 4, testMarkov2, (config.startSymbol, config.startSymbol), 2) 115 | print val[0].totalFieldLen() == 4 116 | print val[0].popFirstNBits(4) == "0001" 117 | print val[1] == 3 118 | print "E:" 119 | val = decodeWordListToBits(['A', 'A', 'A'], 4, testMarkov) 120 | print val[0].totalFieldLen() == 4 121 | print val[0].popFirstNBits(4) == "0000" 122 | print val[1] == 3 123 | print "F:" 124 | val = decodeWordListToBits(['C', 'A'], 3, testMarkov) 125 | print val[0].totalFieldLen() == 3 126 | print val[0].popFirstNBits(3) == "110" 127 | print val[1] == 2 128 | print "G:" 129 | val = decodeWordListToBits(['A', 'B', 'B', 'B', 'B', 'A', 'A', 'C', 'C', 'C', 'C', '', 'B', 'B', 'B', 'B', 'B', 'C', '', 'A', 'C', 'C', 'C', 'A', '', 'B', 'C', 'C', 'C', 'C', 'B', 'A', '', 'B', '', 'A', 'C', 'C', '', 'A', 'C', 'C', 'C', 'C', 'C', 'C', 'A', '', 'B', 'C', 'C', 'C'], 100, testMarkov) 130 | print val[0].totalFieldLen() == 100 131 | print val[0].popFirstNBits(100) == "0010101010000101010101110010101011011010101000111010101010010011101101010110101010101010001110101010" 132 | print val[1] == 52 133 | print "H:" 134 | # like G, but adding more words, to see how it detects where to finish 135 | val = decodeWordListToBits(['A', 'B', 'B', 'B', 'B', 'A', 'A', 'C', 'C', 'C', 'C', '', 'B', 'B', 'B', 'B', 'B', 'C', '', 'A', 'C', 'C', 'C', 'A', '', 'B', 'C', 'C', 'C', 'C', 'B', 'A', '', 'B', '', 'A', 'C', 'C', '', 'A', 'C', 'C', 'C', 'C', 'C', 'C', 'A', '', 'B', 'C', 'C', 'C', 'A', 'A', 'B', 'A'], 100, testMarkov) 136 | print val[0].totalFieldLen() == 100 137 | print val[0].popFirstNBits(100) == "0010101010000101010101110010101011011010101000111010101010010011101101010110101010101010001110101010" 138 | print val[1] == 52 139 | print "I:" 140 | val = decodeWordListToBits(['B', 'C', '', 'B', 'C', '', 'C', 'B', 'B', 'C', 'C', '', 'C', 'C', 'C', 'C', 'B', 'B', 'B', 'B', 'A', 'C', '', 'C', 'B', 'B', ''], 54, testMarkov) 141 | print val[0].totalFieldLen() == 54 142 | print val[0].popFirstNBits(54) == "101011101011110101101011111010100101010100101111010111" 143 | print val[1] == 27 144 | print "J:" 145 | # like I, but adding more words, to see how it detects where to finish 146 | val = decodeWordListToBits(['B', 'C', '', 'B', 'C', '', 'C', 'B', 'B', 'C', 'C', '', 'C', 'C', 'C', 'C', 'B', 'B', 'B', 'B', 'A', 'C', '', 'C', 'B', 'B', '', 'B', 'C', '', 'C', 'B', 'B', 'C', 'C'], 54, testMarkov) 147 | print val[0].totalFieldLen() == 54 148 | print val[0].popFirstNBits(54) == "101011101011110101101011111010100101010100101111010111" 149 | print val[1] == 27 150 | print "J2:" 151 | # like I, but adding more words, to see how it detects where to finish 152 | val = decodeWordListToBits(['B', 'C', '', 'B', 'C', '', 'C', 'B', 'B', 'C', 'C', '', 'C', 'C', 'C', 'C', 'B', 'B', 'B', 'B', 'A', 'C', '', 'C', 'B', 'B', '', 'B', 'C', '', 'C', 'B', 'B', 'C', 'C'], 54, 153 | testMarkov2, (config.startSymbol, config.startSymbol), 2) 154 | print val[0].totalFieldLen() == 54 155 | print val[0].popFirstNBits(54) == "101011101011110101101011111010100101010100101111010111" 156 | print val[1] == 27 157 | 158 | print "done" 159 | 160 | -------------------------------------------------------------------------------- /fixedSizeExamples.py: -------------------------------------------------------------------------------- 1 | "generates the examples shown in the paper, for fixed size encoding" 2 | import config 3 | import utils 4 | import bigBitField 5 | import fixedSizeCode 6 | 7 | def testExample(data, markovChain): 8 | print "---" 9 | print "input: "+repr(data) 10 | miniBF = bigBitField.BigBitField(data, False) 11 | print "output: "+ repr(fixedSizeCode.encodeBitsToWordList(miniBF, markovChain, config.startSymbol, 1)) 12 | 13 | mc = [ 14 | [config.startSymbol, [ ["s1", [1, 2]], ["s2", [1, 2]] ]], 15 | ["s1", [ ["s3", [1, 5]], ["s4", [4, 5]] ]], 16 | ["s2", [ ["s4", [1, 4]], ["s5", [3, 4]] ]], 17 | ["s3", [ [config.startSymbol, [1, 1]] ]], 18 | ["s4", [ ["s6", [3, 10]], ["s7", [7, 10]] ]], 19 | ["s5", [ ["s7", [1, 10]], ["s8", [9, 10]] ]], 20 | ["s6", [ [config.startSymbol, [1, 1]] ]], 21 | ["s7", [ [config.startSymbol, [1, 1]] ]], 22 | ["s8", [ [config.startSymbol, [1, 1]] ]] 23 | ] 24 | 25 | 26 | testExample("0", mc) 27 | testExample("1", mc) 28 | testExample("00", mc) 29 | testExample("01", mc) 30 | testExample("10", mc) 31 | testExample("11", mc) 32 | testExample("000", mc) 33 | testExample("001", mc) 34 | testExample("010", mc) 35 | testExample("011", mc) 36 | testExample("100", mc) 37 | testExample("101", mc) 38 | testExample("110", mc) 39 | testExample("111", mc) 40 | testExample("0000", mc) 41 | testExample("0001", mc) 42 | testExample("0010", mc) 43 | testExample("0011", mc) 44 | testExample("0100", mc) 45 | testExample("0101", mc) 46 | testExample("0110", mc) 47 | testExample("0111", mc) 48 | testExample("1000", mc) 49 | testExample("1001", mc) 50 | testExample("1010", mc) 51 | testExample("1011", mc) 52 | testExample("1100", mc) 53 | testExample("1101", mc) 54 | testExample("1110", mc) 55 | testExample("1111", mc) 56 | testExample("00000", mc) 57 | testExample("11111", mc) 58 | 59 | -------------------------------------------------------------------------------- /markov.py: -------------------------------------------------------------------------------- 1 | import json 2 | import math 3 | import re 4 | import random 5 | 6 | import utils 7 | import config 8 | 9 | # CONFIG 10 | minLineLen = 4 11 | 12 | 13 | def countRepeatedWords(words): 14 | # given a list of words, count how many times each one is listed; case insensitive 15 | count = {} 16 | 17 | for word in words: 18 | w = word.lower() 19 | 20 | if w in count: 21 | count[w] = (word, count[w][1] + 1) 22 | else: 23 | count[w] = (word, 1) 24 | 25 | return count.values() 26 | 27 | 28 | def computeProbabilities(words): 29 | # given a list of words, compute the probability (in a fraction) for each word 30 | count = countRepeatedWords(words) 31 | 32 | total = sum([c[1] for c in count]) 33 | return [(c[0], (c[1], total)) for c in count] 34 | 35 | # wordsPerState is either 1 (the chain keeps probabilities per bigram; 1 input word to 1 output word) or 2 36 | # (the chain keeps probabilities for each 2 input words that go to 1 output word) 37 | def createMarkovChain(inputData, wordsPerState): 38 | # split sentences, get bigrams 39 | lines = [re.findall(r"\w[\w']*", line) for line 40 | in re.split(r"\r\n\r\n|\n\n|\,|\.|\!", inputData)] 41 | lines = [[config.startSymbol] + line + [config.startSymbol] for line 42 | in lines if len(line) >= minLineLen] 43 | 44 | if wordsPerState == 1: 45 | bigrams = [[(line[word], line[word+1]) for word in range(len(line)-1)] for line in lines] 46 | elif wordsPerState == 2: 47 | bigrams1 = [[(line[word], line[word+1], line[word+2]) for word in range(len(line)-2)] for line in lines] 48 | # add special (start, start) -> out cases 49 | bigrams2 = [[(line[0], line[0], line[1])] for line in lines] 50 | bigrams = bigrams1 + bigrams2 51 | else: 52 | raise RuntimeError("wordsPerState should be either 1 or 2 only") 53 | 54 | # compute markov chain 55 | # in this context, we call bigrams the pairs (input state, output state); not the best name 56 | # when the input state has more than 1 word unfortunately 57 | bigramsDict = {} 58 | 59 | def addBigramToDict(word1, word2): 60 | word1b = utils.lowerWordOrList(word1) 61 | 62 | if word1b in bigramsDict: 63 | (w1, w2) = bigramsDict[word1b] 64 | w2.append(word2) 65 | else: 66 | bigramsDict[word1b] = (word1, [word2]) 67 | 68 | for line in bigrams: 69 | for bigram in line: 70 | if wordsPerState == 1: 71 | addBigramToDict(bigram[0], bigram[1]) 72 | elif wordsPerState == 2: 73 | addBigramToDict((bigram[0], bigram[1]), bigram[2]) 74 | 75 | fullBigrams = bigramsDict.values() 76 | 77 | fullBigrams = [(bigram[0], computeProbabilities(bigram[1])) for bigram in fullBigrams] 78 | # at this point, fullBigrams contains the markovChain with probabilities in fractions 79 | 80 | return fullBigrams 81 | 82 | 83 | # wordsPerState is either 1 (the chain keeps probabilities per bigram; 1 input word to 1 output word) or 2 84 | # (the chain keeps probabilities for each 2 input words that go to 1 output word) 85 | def createMarkovChainFromFile(inputFile, outputFile, wordsPerState): 86 | f = open(inputFile, 'r') 87 | inputData = f.read() 88 | f.close() 89 | 90 | bigrams = createMarkovChain(inputData, wordsPerState) 91 | 92 | # save 93 | jsonData = json.JSONEncoder().encode(bigrams) 94 | f = open(outputFile, 'w') 95 | f.write(jsonData) 96 | f.close() 97 | 98 | 99 | 100 | # check markov file 101 | def testMarkovChain(inputMarkov): 102 | f = open(inputMarkov, 'r') 103 | jsonData = f.read() 104 | f.close() 105 | 106 | data = json.JSONDecoder().decode(jsonData) 107 | 108 | errors = 0 109 | 110 | for bigram in data: 111 | (wordFrom, wordsTo) = bigram 112 | total = wordsTo[0][1][1] 113 | total2 = 0 114 | 115 | for word in wordsTo: 116 | total2 = total2 + word[1][0] 117 | 118 | if total != total2: 119 | print "error, denominator and total numerators are different!" 120 | 121 | 122 | if errors == 0: 123 | print "OK: no errors found in markov file" 124 | else: 125 | print "ERROR: " + repr(errors) + " errors found in markov file" 126 | 127 | 128 | # input is a markov chain 129 | # see createMarkovChain for a description of the parameter wordsPerState 130 | def generateTextUsingMarkovChain(inputMarkov, wordsPerState): 131 | f = open(inputMarkov, 'r') 132 | jsonData = f.read() 133 | f.close() 134 | 135 | data = json.JSONDecoder().decode(jsonData) 136 | 137 | words = [] 138 | if wordsPerState == 1: 139 | prev = config.startSymbol 140 | elif wordsPerState == 2: 141 | prev = (config.startSymbol, config.startSymbol) 142 | 143 | markovDict = {} 144 | for bigram in data: 145 | markovDict[utils.lowerWordOrList(utils.listToTuple(bigram[0]))] = bigram[1] 146 | 147 | while True: 148 | m = markovDict[utils.lowerWordOrList(prev)] 149 | denominator = m[0][1][1] 150 | rnd = random.randint(1, denominator) 151 | total = 0 152 | nextWord = None 153 | 154 | for word in m: 155 | total = total + word[1][0] 156 | if total >= rnd: 157 | nextWord = word[0] 158 | break 159 | 160 | if nextWord == config.startSymbol: 161 | break 162 | 163 | words.append(nextWord) 164 | 165 | if wordsPerState == 1: 166 | prev = nextWord 167 | elif wordsPerState == 2: 168 | prev = (prev[1], nextWord) 169 | 170 | return words 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | import config 2 | import math 3 | import re 4 | 5 | def wordListToText(strl): 6 | text = "" 7 | lastWord = config.startSymbol 8 | 9 | for word in strl: 10 | if lastWord == config.startSymbol and word != config.startSymbol: 11 | word = word[0].capitalize() + word[1:] 12 | 13 | if word != config.startSymbol and text != "": 14 | text = text + " " 15 | 16 | if not(text == "" and word == config.startSymbol): 17 | if word == config.startSymbol: 18 | text = text + "." 19 | else: 20 | text = text + word 21 | 22 | lastWord = word 23 | 24 | 25 | return text.rstrip("") 26 | 27 | def textToWordList(text): 28 | words = re.findall(r"(?:\w[\w']*)|\.", text) 29 | 30 | def convert(w): 31 | if w == ".": 32 | return config.startSymbol 33 | else: 34 | return w.lower() 35 | 36 | words = [convert(w) for w in words] 37 | 38 | return words 39 | 40 | def fromBinary(numberStr): 41 | return int(numberStr, 2) 42 | 43 | def toBinary(number, minDigits): 44 | binary = bin(number)[2:] 45 | 46 | if len(binary) < minDigits: 47 | binary = "".join(["0" for x in range(minDigits - len(binary))]) + binary 48 | 49 | return binary 50 | 51 | def binaryLowerThan(a, b): 52 | if len(a) != len(b): 53 | raise RuntimeError("can't compare two binary numbers of different size") 54 | else: 55 | return a < b 56 | 57 | def binaryLowerEqualThan(a, b): 58 | return (a == b or binaryLowerThan(a, b)) 59 | 60 | """ 61 | this function expands digitRanges to make them cover at least as many values as those in desiredRangeLen 62 | 63 | - digitRanges: the actual range of digits 64 | - rangeNums: the ranges already converted to integers 65 | - desiredRangeLen: length goal; how many numbers must contain the range (eg. if this value is 256, the range needs 8 bits) 66 | - maxDigits: max length allowed for the range, in bits 67 | """ 68 | def addDigitsToRange(digitRanges, rangeNums, desiredRangeLen, maxDigits): 69 | 70 | rangePossibleValues = 1 + rangeNums[1] - rangeNums[0] 71 | 72 | if desiredRangeLen <= rangePossibleValues: 73 | return digitRanges 74 | 75 | extraDigitsCount = int(math.ceil(math.log(1.0 * desiredRangeLen / rangePossibleValues, 2))) 76 | if len(digitRanges[0]) + extraDigitsCount > maxDigits: 77 | extraDigitsCount = maxDigits - len(digitRanges[0]) 78 | 79 | digitRanges = ( 80 | digitRanges[0] + "".join(["0" for x in range(extraDigitsCount)]), 81 | digitRanges[1] + "".join(["1" for x in range(extraDigitsCount)]) 82 | ) 83 | 84 | return digitRanges 85 | 86 | """ 87 | - digitRanges: a pair of binary numbers (strings), telling what the range to subdivide is 88 | - wordProbabilities: a list of elements in this format: (word, (numerator, denominator)) 89 | - maxDigits: maximum digits possible in the digit ranges 90 | 91 | returns a list of elements in this format: (word, range) 92 | """ 93 | def computeWordRanges(digitRanges, wordProbabilities, maxDigits): 94 | 95 | denominator = wordProbabilities[0][1][1] 96 | rangeNums = (fromBinary(digitRanges[0]), fromBinary(digitRanges[1])) 97 | 98 | # add more binary digits to range, if needed 99 | digitRanges = addDigitsToRange(digitRanges, rangeNums, denominator, maxDigits) 100 | 101 | rangeNums = (fromBinary(digitRanges[0]), fromBinary(digitRanges[1])) 102 | 103 | totalDigits = len(digitRanges[0]) 104 | 105 | # typical double is 53 bits long; we limit range to some lower amount of bits 106 | if math.log(max(1, abs(rangeNums[1] - rangeNums[0])), 2) > 45: 107 | raise RuntimeError("error; range too long") 108 | 109 | # compute word ranges 110 | # first we compute float ranges, then we distribute the actual integer ranges as well as possible 111 | step = (1.0 * (rangeNums[1] - rangeNums[0])) / denominator 112 | 113 | base = rangeNums[0] 114 | start = 0 115 | 116 | wordRanges = [] 117 | for wordP in wordProbabilities: 118 | end = start + wordP[1][0] * step 119 | 120 | wordRanges.append([wordP[0], [start, end]]) 121 | start = end 122 | 123 | # the last element could be wrong because of float precision problems, force it 124 | # it is very important that we force this change in wordRanges and not in wordRanges2; otherwise the list could lose extra elements 125 | wordRanges[-1][1][1] = rangeNums[1] - base 126 | 127 | start = 0 128 | 129 | wordRanges2 = [] 130 | for wordR in wordRanges: 131 | if wordR[1][1] >= start: 132 | wordR2 = [wordR[0], [start, int(math.floor(wordR[1][1]))]] 133 | wordR3 = [wordR2[0], [wordR2[1][0]+base, wordR2[1][1]+base]] 134 | wordRanges2.append(wordR3) 135 | 136 | start = wordR2[1][1] + 1 137 | 138 | # convert to binary before returning 139 | return [ 140 | (wordP[0], (toBinary(wordP[1][0], totalDigits), toBinary(wordP[1][1], totalDigits))) 141 | for wordP in wordRanges2] 142 | 143 | # given a range, removes its common digits (excepting the last one); doesn't modify the original range object 144 | def removeCommonBitsInRange(rangeDigits): 145 | while len(rangeDigits[0]) > 1 and rangeDigits[0][0] == rangeDigits[1][0]: 146 | rangeDigits = (rangeDigits[0][1:], rangeDigits[1][1:]) 147 | 148 | return rangeDigits 149 | 150 | # converts an integer to a list of bytesCount bytes 151 | def convertNumberToByteList(number, bytesCount): 152 | bytes = [] 153 | 154 | for i in range(bytesCount): 155 | b = number % 256 156 | number = (number - b) / 256 157 | bytes.insert(0, b) 158 | 159 | bytes.reverse() 160 | return bytes 161 | 162 | # converts an integer to a list of bytesCount bytes 163 | def convertByteListToNumber(bytes): 164 | number = 0 165 | 166 | for b in reversed(bytes): 167 | number = number * 256 + b 168 | 169 | return number 170 | 171 | # set all words to lower case, except the start symbol 172 | def lowerWord(w): 173 | if w != config.startSymbol: 174 | return w.lower() 175 | else: 176 | return w 177 | 178 | 179 | def lowerWordOrList(word): 180 | if type(word) is list: 181 | return [lowerWord(w) for w in word] 182 | elif type(word) is tuple: 183 | return tuple([lowerWord(w) for w in word]) 184 | else: 185 | return lowerWord(word) 186 | 187 | def listToTuple(t): 188 | if type(t) == list: 189 | return tuple(t) 190 | else: 191 | return t 192 | 193 | def markovChainToDictionary(markovChain): 194 | dictionary = {} 195 | 196 | for wp in markovChain: 197 | dictionary[lowerWordOrList(listToTuple(wp[0]))] = wp 198 | 199 | return dictionary 200 | 201 | if __name__ == '__main__': 202 | print "testing utils.py" 203 | print "TEST 1" 204 | print (computeWordRanges(["0", "1"], [("casa", (1, 4)), ("bosque", (2, 4)), ("selva", (1, 4))], 3) == 205 | [('casa', ('00', '00')), ('bosque', ('01', '10')), ('selva', ('11', '11'))]) 206 | print "TEST 2" 207 | print (computeWordRanges(["0", "1"], [("casa", (1, 5)), ("bosque", (2, 5)), ("selva", (2, 5))], 1) == 208 | [('casa', ('0', '0')), ('selva', ('1', '1'))]) 209 | print "TEST 3" 210 | print (computeWordRanges(["0", "0"], [("casa", (1, 5)), ("bosque", (2, 5)), ("selva", (2, 5))], 5) == 211 | [('casa', ('0000', '0001')), ('bosque', ('0010', '0100')), ('selva', ('0101', '0111'))]) 212 | print "TEST 4" 213 | print (computeWordRanges(["0", "0"], [("casa", (1, 5)), ("bosque", (2, 5)), ("selva", (2, 5))], 3) == 214 | [('casa', ('000', '000')), ('bosque', ('001', '001')), ('selva', ('010', '011'))]) 215 | print "TEST 5" 216 | print (computeWordRanges(["0", "1"], [("casa", (1, 3)), ("bosque", (1, 3)), ("selva", (1, 3))], 30) == 217 | [('casa', ('00', '01')), ('bosque', ('10', '10')), ('selva', ('11', '11'))]) 218 | print "TEST 6" 219 | bytes = convertNumberToByteList(342432, 3) 220 | print bytes == [160, 57, 5] 221 | print convertByteListToNumber(bytes) == 342432 222 | print "TEST 7" 223 | bytes = convertNumberToByteList(127, 1) 224 | print bytes == [127] 225 | print convertByteListToNumber(bytes) == 127 226 | print "TEST 8" 227 | bytes = convertNumberToByteList(123456, 3) 228 | print bytes == [64, 226, 1] 229 | print convertByteListToNumber(bytes) == 123456 230 | print "TEST 9" 231 | print wordListToText(["word1","word2","word3","","word4","","word5"]) == "Word1 word2 word3. Word4. Word5" 232 | print "TEST 10" 233 | print textToWordList("Word1 word2 word3. Word4. Word5") == ["word1","word2","word3","","word4","","word5"] 234 | print "done" 235 | 236 | 237 | -------------------------------------------------------------------------------- /variableSizeCode.py: -------------------------------------------------------------------------------- 1 | "encode and decode to and from variable size" 2 | import config 3 | import utils 4 | import bigBitField 5 | import fixedSizeCode 6 | import fixedSizeDecode 7 | import json 8 | import time 9 | 10 | """ 11 | encodes variable sized data to text 12 | 13 | - data: data to be encoded (a list of integers, every one is a byte) 14 | - bitsForSize: how many bits will be used to encode the size 15 | - markovChain: markov chainto use 16 | 17 | returns the encoded text 18 | """ 19 | def encodeDataToWordList(data, bytesForSize, markovChain, wordsPerState = 1): 20 | 21 | # encode the data length first 22 | lenData = utils.convertNumberToByteList(len(data), bytesForSize) 23 | bitsField = bigBitField.BigBitField(lenData) 24 | 25 | if wordsPerState == 1: 26 | lastWord = config.startSymbol 27 | elif wordsPerState == 2: 28 | lastWord = (config.startSymbol, config.startSymbol) 29 | 30 | lenDataCode = fixedSizeCode.encodeBitsToWordList(bitsField, markovChain, lastWord, wordsPerState) 31 | 32 | # compute last word (or bigram) 33 | if wordsPerState == 1: 34 | lastWord = lenDataCode[-1] 35 | elif wordsPerState == 2: 36 | if len(lenDataCode) <= 1: 37 | lastWord = (config.startSymbol, lenDataCode[-1]) 38 | else: 39 | lastWord = (lenDataCode[-2], lenDataCode[-1]) 40 | 41 | if lastWord[1] == config.startSymbol: 42 | lastWord = (config.startSymbol, config.startSymbol) 43 | 44 | # encode the actual message 45 | bitsField = bigBitField.BigBitField(data) 46 | mainDataCode = fixedSizeCode.encodeBitsToWordList(bitsField, markovChain, lastWord, wordsPerState) 47 | 48 | return lenDataCode + mainDataCode 49 | 50 | """ 51 | decodes a text to data (variable sized data) 52 | 53 | - wordList: encoded data in a text 54 | - bitsForSize: how many bits will be used to encode the size 55 | - markovChain: markov chainto use 56 | 57 | returns the decoded data (in a bigBitField object) 58 | """ 59 | def decodeWordListToData(wordList, bytesForSize, markovChain, wordsPerState = 1): 60 | 61 | if wordsPerState == 1: 62 | lastWord = config.startSymbol 63 | elif wordsPerState == 2: 64 | lastWord = (config.startSymbol, config.startSymbol) 65 | 66 | # decode the message length 67 | (lenRawData, wordsUsed) = fixedSizeDecode.decodeWordListToBits(wordList, bytesForSize * 8, markovChain, lastWord, wordsPerState) 68 | lenRawData = lenRawData.getAllBytes() 69 | lenData = utils.convertByteListToNumber(lenRawData) 70 | 71 | # compute last word (or bigram) 72 | if wordsPerState == 1: 73 | lastWord = wordList[wordsUsed - 1] 74 | elif wordsPerState == 2: 75 | if wordsUsed == 1: 76 | lastWord = (config.startSymbol, wordList[wordsUsed - 1]) 77 | elif wordsUsed == 0: 78 | raise RuntimeError("only 0 words used in decode word list to data") 79 | else: 80 | lastWord = (wordList[wordsUsed - 2], wordList[wordsUsed - 1]) 81 | 82 | if lastWord[1] == config.startSymbol: 83 | lastWord = (config.startSymbol, config.startSymbol) 84 | 85 | # decode the actual message 86 | wordList = wordList[wordsUsed:] 87 | (decodedData, wordsUsed) = fixedSizeDecode.decodeWordListToBits(wordList, lenData * 8, markovChain, lastWord, wordsPerState) 88 | 89 | return decodedData 90 | 91 | 92 | # given 2 input files, encode and save to the output file 93 | def encodeDataFromFile(inputFile, outputFile, markovInputFile, textFileFormat, wordsPerState = 1): 94 | initTime = time.time() 95 | 96 | f = open(markovInputFile, 'r') 97 | jsonData = f.read() 98 | f.close() 99 | markovData = json.JSONDecoder().decode(jsonData) 100 | 101 | if (wordsPerState == 1 and type(markovData[0][0]) != str and type(markovData[0][0]) != unicode) or (wordsPerState == 2 and type(markovData[0][0]) != list): 102 | raise RuntimeError("error; markov chain structure doesn't match wordsPerState value") 103 | 104 | inputData = [] 105 | f = open(inputFile, 'rb') 106 | char = None 107 | while char != "": 108 | char = f.read(1) 109 | if char != "": inputData.append(ord(char)) 110 | f.close() 111 | 112 | initTimeCode = time.time() 113 | 114 | encodedData = encodeDataToWordList(inputData, 4, markovData, wordsPerState) 115 | 116 | # save 117 | if textFileFormat: 118 | outputData = utils.wordListToText(encodedData) 119 | else: 120 | outputData = json.JSONEncoder().encode(encodedData) 121 | 122 | endTimeCode = time.time() 123 | 124 | f = open(outputFile, 'w') 125 | f.write(outputData) 126 | f.close() 127 | 128 | print "wrote " + repr(len(inputData) * 8) + " bits" 129 | print "elapsed time: " + repr(time.time() - initTime) + " seconds" 130 | print " - encoding time: " + repr(endTimeCode - initTimeCode) + " seconds" 131 | 132 | # given 2 input files, decode and save to the output file 133 | def decodeDataFromFile(inputFile, outputFile, markovInputFile, textFileFormat, wordsPerState = 1): 134 | initTime = time.time() 135 | 136 | f = open(markovInputFile, 'r') 137 | jsonData = f.read() 138 | f.close() 139 | markovData = json.JSONDecoder().decode(jsonData) 140 | 141 | if (wordsPerState == 1 and type(markovData[0][0]) != str and type(markovData[0][0]) != unicode) or (wordsPerState == 2 and type(markovData[0][0]) != list): 142 | raise RuntimeError("error; markov chain structure doesn't match wordsPerState value") 143 | 144 | f = open(inputFile, 'r') 145 | inputData = f.read() 146 | f.close() 147 | 148 | initTimeDecode = time.time() 149 | if textFileFormat: 150 | inputData = utils.textToWordList(inputData) 151 | else: 152 | inputData = json.JSONDecoder().decode(inputData) 153 | 154 | decodedData = decodeWordListToData(inputData, 4, markovData, wordsPerState) 155 | print "read " + repr(decodedData.totalFieldLen()) + " bits" 156 | decodedData = decodedData.getAllBytes() 157 | endTimeDecode = time.time() 158 | 159 | # save 160 | f = open(outputFile, 'wb') 161 | for b in decodedData: 162 | f.write(chr(b)) 163 | f.close() 164 | 165 | print "elapsed time: " + repr(time.time() - initTime) + " seconds" 166 | print " - decoding time: " + repr(endTimeDecode - initTimeDecode) + " seconds" 167 | 168 | 169 | if __name__ == '__main__': 170 | print "testing variableSizeCode.py" 171 | print "A:" 172 | testMarkov = config.testMarkov 173 | data = [70, 90, 255, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 22, 211, 32, 89, 32, 89, 32, 89, 90,221, 111, 231, 89, 3, 3, 2, 1, 34, 55, 255, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 22, 211, 32, 89, 32, 89, 32, 89, 90,221, 111, 231, 89, 3, 3, 2, 1, 34, 55, 255, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 22, 211, 32, 89, 32, 89, 32, 89, 90,221, 111, 231, 89, 3, 3, 2, 1, 34, 55] 174 | code = encodeDataToWordList(data, 1, testMarkov) 175 | data2field = decodeWordListToData(code, 1, testMarkov) 176 | print data2field.totalFieldLen() == 125 * 8 177 | print code == ['A', '', 'C', 'C', '', 'A', 'C', 'A', '', 'A', 'B', 'B', 'C', 'C', '', 'C', '', 'C', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', 'C', '', 'A', 'C', 'B', 'C', 'B', 'A', 'A', 'A', 'C', '', 'A', 'B', 'A', 'C', 'A', 'A', 'B', 'B', 'C', 'B', 'A', 'C', 'A', 'A', 'B', 'B', 'C', 'B', 'B', 'B', 'C', 'C', '', 'A', '', 'B', 'C', '', 'A', '', 'C', '', 'B', 'B', '', 'A', 'C', '', 'A', 'B', 'A', 'A', 'A', '', 'A', 'A', 'A', 'B', 'C', 'A', 'A', 'B', 'A', 'A', 'A', 'A', 'C', 'B', 'A', 'B', 'A', 'B', 'C', '', 'C', '', 'C', '', 'B', 'A', 'C', '', 'B', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', 'C', '', 'A', 'C', 'B', 'C', 'B', 'A', 'A', 'A', 'C', '', 'A', 'B', 'A', 'C', 'A', 'A', 'B', 'B', 'C', 'B', 'A', 'C', 'A', 'A', 'B', 'B', 'C', 'B', 'B', 'B', 'C', 'C', '', 'A', '', 'B', 'C', '', 'A', '', 'C', '', 'B', 'B', '', 'A', 'C', '', 'A', 'B', 'A', 'A', 'A', '', 'A', 'A', 'A', 'B', 'C', 'A', 'A', 'B', 'A', 'A', 'A', 'A', 'C', 'B', 'A', 'B', 'A', 'B', 'C', '', 'C', '', 'C', '', 'B', 'A', 'C', '', 'B', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', '', 'A', '', 'C', 'B', 'B', '', 'A', 'C', 'A', 'A', 'B', 'B', 'C', '', 'A', 'C', 'B', 'C', 'B', 'A', 'A', 'A', 'C', '', 'A', 'B', 'A', 'C', 'A', 'A', 'B', 'B', 'C', 'B', 'A', 'C', 'A', 'A', 'B', 'B', 'C', 'B', 'B', 'B', 'C', 'C', '', 'A', '', 'B', 'C', '', 'A', '', 'C', '', 'B', 'B', '', 'A', 'C', '', 'A', 'B', 'A', 'A', 'A', '', 'A', 'A', 'A', 'B', 'C', 'A', 'A', 'B', 'A', 'A', 'A', 'A', 'C', 'B', 'A', 'B', 'A', 'B', 'C', '', 'C'] 178 | print len(code) == 537 179 | print data2field.getAllBytes() == data 180 | 181 | 182 | print "B:" 183 | data = [70, 90, 255, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 22, 211, 32, 89, 32, 89, 32, 89, 90,221, 111, 231, 89, 3, 3, 2, 1, 34, 55, 255, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 22, 211, 32, 89, 32, 89, 32, 89, 90,221, 111, 231, 89, 3, 3, 2, 1, 34, 55, 255, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 23, 122, 232, 22, 211, 32, 89, 32, 89, 32, 89, 90,221, 111, 231, 89, 3, 3, 2, 1, 34, 55] 184 | f = open("data/markovChain.json", 'r') 185 | jsonData = f.read() 186 | f.close() 187 | bigMarkov = json.JSONDecoder().decode(jsonData) 188 | 189 | code = encodeDataToWordList(data, 1, bigMarkov) 190 | data2field = decodeWordListToData(code, 1, bigMarkov) 191 | print data2field.totalFieldLen() == len(data) * 8 192 | print code == [u'running', u'away', u'from', u'my', u'friend', u'as', u'before', u'us', u'', u'the', u'French', u'followed', u'behind', u'', u'and', u'to', u'conclude', u'will', u'not', u'only', u'a', u'printed', u'matter', u'of', u'freedom', u'and', u'solemn', u'hymn', u'', u'and', u'the', u'luring', u'Napoleon', u'', u'middle', u'of', u'sick', u'father', u'', u'replied', u'Nicholas', u'ran', u'into', u'tears', u'', u'I', u"don't", u'know', u'they', u'describe', u'an', u'active', u'and', u'second', u'autocrat', u'', u'though', u'she', u'needed', u'he', u'ought', u'not', u'worth', u'while', u'still', u'stouter', u'', u'rapidly', u'', u'he', u'excused', u'himself', u'to', u'escape', u'as', u'heralds', u'of', u'so', u'God', u'', u'and', u'ingratiating', u'the', u'generals', u'', u'and', u'having', u'made', u'a', u'moment', u'he', u'was', u'going', u'to', u'go', u'after', u'by', u'any', u'orders', u'Or', u'the', u'middle', u'of', u'it', u'anticipated', u'his', u'wife', u'is', u'all', u'this', u'excess', u'of', u'that', u'he', u'reached', u'the', u'history', u'remains', u'of', u'the', u'room', u'next', u'day', u'', u'being', u'said', u'Princess', u'Mary', u'also', u'by', u'the', u'dressing', u'jacket', u'laced', u'with', u'greedy', u'expectation', u'', u'the', u'end', u'to', u'wash', u'That', u'the', u'immediate', u'answer', u'', u'un', u'moment', u'', u'and', u'zeal', u'than', u'all', u'', u'How', u'strange', u'', u'though', u'what', u'might', u'endanger', u'the', u'snowflakes', u'fluttering', u'dressing', u'gown', u'of', u'the', u'action', u'to', u'pardon'] 193 | print len(code) == 172 194 | print data2field.getAllBytes() == data 195 | print "done" 196 | 197 | --------------------------------------------------------------------------------