Ejemplo n.º 1
0
 def conversation_speak():
     print('you can now write to Bob')
     cipher = AES.new(shared_key, AES.MODE_CBC, b'a' * 16)
     while True:
         text = input().encode()
         ctext = cipher.encrypt(pkcs.pad(text, 16))
         s.sendall(ctext)
Ejemplo n.º 2
0
 def encrypt(self, string):
     string = string.replace(';', '').replace('=', '')
     prefix = "comment1=cooking%20MCs;userdata="
     suffix = ";comment2=%20like%20a%20pound%20of%20bacon"
     m = prefix + string + suffix
     obj = AES.new(self.master_key, 2, self.iv)
     return obj.encrypt(pkcs.pad(m.encode(), 16))
Ejemplo n.º 3
0
 def encrypt(self, msg):
     '''sandwiches msg between two random strings and encrypts under
     ECB or CBC'''
     plaintext = urandom(randint(5, 10)) + msg + urandom(randint(5, 10))
     plaintext = pkcs.pad(plaintext, 16)
     rand_mode = randint(1, 2)
     obj = AES.new(self.k, rand_mode, urandom(16))  #1 = ECB, 2=CBC
     return obj.encrypt(plaintext)
Ejemplo n.º 4
0
def decode_last_block():
    target = target_blocks(0)
    decoded_text = b''
    for char in range(16):
        for i in range(256):
            if sneaky_encryption(pkcs.pad(chr(i).encode()+decoded_text, 16))\
                    in target:
                decoded_text = (chr(i).encode()) + decoded_text
    return decoded_text
Ejemplo n.º 5
0
def encryption_cassandra(msg):
    k = unknown_key
    string = b'Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXk\
        gaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvI\
        HNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK'

    string = b64decode(string)
    msg = msg + string
    plaintext = pkcs.pad(msg, 16)
    from Crypto.Cipher import AES
    obj = AES.new(k, 1, urandom(16))  #1 = ECB, 2=CBC
    return obj.encrypt(plaintext)
Ejemplo n.º 6
0
 def encrypt(self, string):
     iv = urandom(16)
     obj = AES.new(self.master_key, 2, iv)
     return obj.encrypt(pkcs.pad(string.encode(), 16)), iv
Ejemplo n.º 7
0
 def encrypt(self, string):
     obj = AES.new(self.master_key, 2, self.iv)
     return obj.encrypt(pkcs.pad(string.encode(), 16))
Ejemplo n.º 8
0
 def encrypt_profile(self, email):
     'given email, encrypts user profile encoded as string'
     encoded = pkcs.pad(self.profile_for(email).encode(), 16)
     from Crypto.Cipher import AES
     obj = AES.new(self.master_k, 1)
     return obj.encrypt(encoded)