def encrypt_with_fixed_key(plain): #string = "Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK" string = "Um9sbGluJyBpbiBteSA1LjA=" plain = plain + base64.b64decode(string) return ecb_mode.ecb_encrypt(aes_128.aes_128_encrypt, plain, key)
def main(): f = open("ecb_cbc_detect.txt", 'r') plain = f.read() f.close() #print len(plain) plain = my_rand_str(my_rand(11, 5)) + plain plain += my_rand_str(my_rand(11, 5)) #plain = pkcs7.pkcs7_pad(plain, 16) #print len(plain) key = my_rand_str(16) iv = my_rand_byte(16) flag = my_rand(2) cipher = '' if flag == 0: #ecb cipher = ecb_mode.ecb_encrypt(aes_128.aes_128_encrypt, plain, key) print "encrypt mode: ECB" else: #cbc cipher = cbc_mode.cbc_encrypt(aes_128.aes_128_encrypt, iv, plain, key) print "encrypt mode: CBC" #print base64.b64encode(cipher) if not ecb_cbc_detect(cipher): flag -= 1 if flag == 0: print "Detect succeed" else: print "Detect failed"
def main(): key = my_rand_str(16) plain_dic = profile_for("*****@*****.**") plain_cookie = my_encode(plain_dic) plain = plain_cookie print "plain:\n" + plain cipher = ecb_encrypt(aes_128_encrypt, plain, key) plain = ecb_decrypt(aes_128_decrypt, cipher, key) plain_cookie = plain plain_dic = my_decode(plain_cookie) print "plain:\n" + plain
def encrypt_with_fixed_key(plain): plain = prefix_str + plain + suffix_str return ecb_mode.ecb_encrypt(aes_128_encrypt, plain, key)
return matrix_to_list(state) if __name__ == '__main__': key = 'YELLOW SUBMARINE' #encrypt f = open('plain.txt', 'r') plaintext = f.read() f.close(); # padding #plaintext += (16 - (len(plaintext) % 16)) * '\0' #print len(plaintext), ord(plaintext[-1]) #ciphertext = aes_128_ecb_encrypt(plaintext, key) ciphertext = ecb_encrypt(aes_128_encrypt, plaintext, key) f = open('cipher.txt', 'w') b64_ciphertext = base64.b64encode(ciphertext) for i in range(0, len(b64_ciphertext), 60): f.write(b64_ciphertext[i:i+60] + '\n') f.close() #decrypt f = open('aes_128.txt', 'r') b64_ciphertext = f.read() f.close(); ciphertext = base64.b64decode(b64_ciphertext) #plaintext = aes_128_ecb_decrypt(ciphertext, key)