Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import rsa
- from Crypto.Cipher import AES
- def encryption(message_block, key, IV):
- #message = ""
- #message_block_size= len(message_block)
- #array_ciphertext=[]
- #for znak in message_block:
- #message+=znak
- #if len(message)==16:
- #obj = AES.new(key, AES.MODE_CBC, IV)
- #ciphertext = obj.encrypt(message)
- #array_ciphertext.append(ciphertext)
- array_ciphertext=[]
- for i in range(0, len(message_block), 16):
- message = ""
- end_byte = i + 16
- if i + 16 > len(message_block):
- end_byte = len(message_block)
- for byte in range(i, end_byte):
- message = message + bytearray(message_block)
- if i % 16 == 0:
- obj = AES.new(key, AES.MODE_CBC, IV)
- ciphertext = obj.encrypt(message)
- array_ciphertext.append(ciphertext)
- IV=ciphertext
- else:
- residue_value=(i % 16)+1
- payload=16-residue_value
- cyclus_value=0
- if payload<9:
- cyclus_value=payload
- else:
- cyclus_value=payload-1
- for j in range(0,cyclus_value-1):
- message = message + bytearray("0")
- message+=payload
- obj = AES.new(key, AES.MODE_CBC, IV)
- ciphertext = obj.encrypt(message)
- array_ciphertext.append(ciphertext)
- IV = ciphertext
- return array_ciphertext
- return ciphertext
- def decryption(ciphertext, key, IV):
- obj = AES.new(key, AES.MODE_CBC, IV)
- message = obj.decrypt(ciphertext)
- return message
- def main():
- ciphertext = encryption(bytes("The answer is nohdscbjsdabcvabsdsudvfsdabvhbasdhbvhsdbvhasbdhvbsadhv", encoding='utf8'), "This is a key123", 'This is an IV456')
- print(ciphertext)
- #message = decryption(ciphertext, "This is a key123", 'This is an IV456')
- #print(message)
- #message_block=ciphertext
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement