def test_q4(file1, file2): print('Testing encryption over sample file:') plaintext = utilities.file_to_text('plaintext_xcrypt_sample.txt') ciphertext = utilities.file_to_text('ciphertext_xcrypt_sample.txt') key = 82 ciphertext2 = solution.e_xcrypt(plaintext, key) if ciphertext == ciphertext2: print('Encryption Successful') else: print('Encryption failed') plaintext2 = solution.d_xcrypt(ciphertext2, key) if plaintext == plaintext2: print('Decryption Successful') else: print('Decryption failed') print() print('Testing decryption over sample file:') plaintext2 = solution.d_xcrypt(ciphertext2, key) if plaintext == plaintext2: print('Decryption Successful') else: print('Decryption failed') print() plaintext = '' ciphertext = '' ciphertext2 = '' plain4 = file1 cipher4 = file2 key = 0 ciphertext = utilities.file_to_text(cipher4) print('Cryptanalysis of {}:'.format(cipher4)) key, plaintext = solution.cryptanalysis_xcrypt(ciphertext) print('Key found: ', key) print() print('Plaintext:') print(plaintext[:150]) print() print('Cryptanalysis Successful? ', end='') ciphertext2 = solution.e_xcrypt(plaintext, key) if ciphertext == ciphertext2: print('Yes') else: print('No') print() solution.comments_q4() return
def compare(): #alphabet = """poejiqsrbltxwaznfcdhmvgkuy:'" !.?,-#;""" #print(get_baseString()) #print(alphabet) #alphabet = adjust_key(alphabet) var1 = file_to_text("plaintext_xcrypt_sample.txt") print(var1) var2 = solution.d_xcrypt(file_to_text("ciphertext_xcrypt_sample.txt"), 82) print(var2) #var3 = file_to_text("plaintext_subcipher_sample.txt") #print(len(var2)) #print(var2) #print(var3[1073]) #print(var2) for i in range(len(var2)): if var1[i] != var2[i]: print("var1 is: " + var1[i] + "var2 is: " + var2[i]) print(i)