SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. import os
  5. import sys
  6. import rsa
  7. from Crypto.Cipher import AES
  8.  
  9.  
  10. def encryption(message_block, key, IV):
  11.     #message = ""
  12.     #message_block_size= len(message_block)
  13.     #array_ciphertext=[]
  14.     #for znak in message_block:
  15.         #message+=znak
  16.         #if len(message)==16:
  17.             #obj = AES.new(key, AES.MODE_CBC, IV)
  18.             #ciphertext = obj.encrypt(message)
  19.             #array_ciphertext.append(ciphertext)
  20.  
  21.     array_ciphertext=[]
  22.     for i in range(0, len(message_block), 16):
  23.         message = ""
  24.         end_byte = i + 16
  25.         if i + 16 > len(message_block):
  26.             end_byte = len(message_block)
  27.         for byte in range(i, end_byte):
  28.             message = message + bytearray(message_block)
  29.  
  30.  
  31.         if i % 16 == 0:
  32.             obj = AES.new(key, AES.MODE_CBC, IV)
  33.             ciphertext = obj.encrypt(message)
  34.             array_ciphertext.append(ciphertext)
  35.             IV=ciphertext
  36.         else:
  37.             residue_value=(i % 16)+1
  38.             payload=16-residue_value
  39.             cyclus_value=0
  40.             if payload<9:
  41.                 cyclus_value=payload
  42.             else:
  43.                 cyclus_value=payload-1
  44.  
  45.             for j in range(0,cyclus_value-1):
  46.                 message = message + bytearray("0")
  47.             message+=payload
  48.             obj = AES.new(key, AES.MODE_CBC, IV)
  49.             ciphertext = obj.encrypt(message)
  50.             array_ciphertext.append(ciphertext)
  51.             IV = ciphertext
  52.  
  53.  
  54.     return array_ciphertext
  55.  
  56.  
  57.  
  58.     return ciphertext
  59.  
  60. def decryption(ciphertext, key, IV):
  61.     obj = AES.new(key, AES.MODE_CBC, IV)
  62.     message = obj.decrypt(ciphertext)
  63.     return message
  64.  
  65. def main():
  66.  
  67.     ciphertext = encryption(bytes("The answer is nohdscbjsdabcvabsdsudvfsdabvhbasdhbvhsdbvhasbdhvbsadhv", encoding='utf8'), "This is a key123", 'This is an IV456')
  68.     print(ciphertext)
  69.  
  70.     #message = decryption(ciphertext, "This is a key123", 'This is an IV456')
  71.     #print(message)
  72.     #message_block=ciphertext
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. if __name__ == '__main__':
  82.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top