def test_punctuation(self): ''' Caesar (test_punctuation): punctuation should remain unmodified ''' e = Caesar(key=14) original = '!@$%%^&*()_-+={}[]|":;<>,./?' enciphered = e.encipher(original,keep_punct=True) self.assertEqual(original.upper(), enciphered.upper()) e = Caesar(key=14) original = '!@$%%^&*()_-+={}[]|":;<>,./?' enciphered = e.encipher(original,keep_punct=False) self.assertEqual('', enciphered.upper())
def test_decipher(self): ''' Caesar (test_decipher): test known ciphertext->plaintext pairs ''' text = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' declist = ['xyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw', 'vwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu', 'stuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqr', 'pqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmno', 'lmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza'] for i,key in enumerate((3,5,8,11,15,0,25)): dec = Caesar(key).decipher(text) self.assertEqual(dec.upper(), declist[i].upper())
def test_encipher(self): ''' Caesar (test_encipher): test known plaintext->ciphertext pairs ''' text = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' enclist = ['bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza', 'cdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzab', 'efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd', 'hijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg', 'jklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy'] for i,key in enumerate((1,2,4,7,9,0,25)): enc = Caesar(key).encipher(text) self.assertEqual(enc.upper(), enclist[i].upper())
def test_punctuation(self): ''' Caesar (test_punctuation): punctuation should remain unmodified ''' e = Caesar(key=14) original = '!@$%%^&*()_-+={}[]|":;<>,./?' enciphered = e.encipher(original, keep_punct=True) self.assertEqual(original.upper(), enciphered.upper()) e = Caesar(key=14) original = '!@$%%^&*()_-+={}[]|":;<>,./?' enciphered = e.encipher(original, keep_punct=False) self.assertEqual('', enciphered.upper())
def constructDataset(): ds = SupervisedDataSet(50,50) for line in open("C:\Users\maxence\Documents\data.txt"): input=normalizedDataset(line) cipher = ceas.encipher(line) #print cipher output = normalizedDataset(cipher) #print input #print output ds.addSample( input, output ) ds.saveToFile('C:\\Users\\maxence\\Documents\\ds.xml') return ds ceas = Caesar() if os.path.isfile('C:\\Users\\maxence\\Documents\\net.xml'): print 'Loading Net from file' net=NetworkReader.readFrom('C:\\Users\\maxence\\Documents\\net.xml') else: print 'Building Network' net = buildNetwork(50, 150, 50, bias=True, hiddenclass=TanhLayer) #50 char max #Normaliazed between -1 and 1 on ASCII 255, 0 for empty char,-1,993=1 if os.path.isfile('C:\\Users\\maxence\\Documents\\ds.xml'): print 'Loading Dataset from file' ds = SupervisedDataSet.loadFromFile('C:\\Users\\maxence\\Documents\\ds.xml') else: print 'Building Dataset'