def test_bad_keysize_speck(self): for bad_ksize in self.not_key_sizes: with pytest.raises(KeyError): SpeckCipher(0, key_size=bad_ksize)
def test_bad_modes_speck(self): for bad_mode in self.not_block_modes: with pytest.raises(ValueError): SpeckCipher(0, mode=bad_mode)
def test_bad_blocksizes_speck(self): for bad_bsize in self.not_block_sizes: with pytest.raises(KeyError): SpeckCipher(0, block_size=bad_bsize)
def test_bad_counters_speck(self): for bad_counter in self.not_ints: with pytest.raises(TypeError): SpeckCipher(0, counter=bad_counter)
def test_bad_ivs_speck(self): for bad_iv in self.not_ints: with pytest.raises(TypeError): SpeckCipher(0, init=bad_iv)
def CWMAC(k1, k2, N, M): B = SpeckCipher(k1, key_size=128, block_size=64) P = UH(k2, M) ciphertext = B.encrypt(N) ciphertext = ciphertext ^ P #xor return ciphertext
def test_bad_keys_speck(self): for bad_key in self.not_ints: with pytest.raises(TypeError): SpeckCipher(bad_key)
def decrypt(self, ciphertext): out = "" for n in ciphertext.split("."): out += str(SpeckCipher(self.key).decrypt(int(n))) return self.decode(int(out))
def __init__(self, key, alphabet, key_size, block_size): self.cipher = SpeckCipher(key, key_size=key_size, block_size=block_size) self.codec = BaseCodec(alphabet, bits=block_size) self.max_id = 2**block_size
def speck128_Cipher(k, iv, p): #set by default to 128 bit size... cbc_cipher = SpeckCipher(k, mode='CBC', init=iv) speck_cbc_ciphertext = cbc_cipher.encrypt(p) return speck_cbc_ciphertext
import seccure from speck import SpeckCipher from simon import SimonCipher my_speck = SpeckCipher(0x123456789ABCDEF00FEDCBA987654321) my_simon = SimonCipher(0xABBAABBAABBAABBAABBAABBAABBAABBA) def generatePublicKey(): private_Key = 'prueba1' public_key = seccure.passphrase_to_pubkey(private_Key.encode()) print(public_key) return public_key def cipherText(texto): #print ('escriba texto a cifrar') #simpleText= input() cipher_Text = seccure.encrypt(texto.encode(),str(generatePublicKey()).encode()) # print(cipher_Text) return cipher_Text def decriptText(cipherText): private_key = 'prueba1' text = seccure.decrypt(cipherText, private_key.encode()) print(text) return text def cipherTextSpeck (): text = 0xCCCCAAAA55553333 speck_ciphertext = my_speck.encrypt(text) print (speck_ciphertext)
#Written by Aritra Ray #the library was installed using #pip3 install simonspeckciphers #importing the ciphers from speck import SpeckCipher #initialising the cipher object that is an encyption key my_speck = SpeckCipher(0xABC125) #here we initialized with an encryption key of 11256101 #that is, 0xABC125 when converted to hexadecimal #my_plaintext contains the text that is to be encrypted my_plaintext = 0x111 #Say, we want to encrypt 273. #We have thus entered 0x111, which is the hexadecimal value for 273 #encrypt() is the function by which the plaintext gets converted to ciphertext speck_ciphertext = my_speck.encrypt(my_plaintext) print("The encrypted message is") print(speck_ciphertext) #the encrypted message was displayed #decrypt() is the function by which the ciphertext gets converted to plaintext speck_plaintext = my_speck.decrypt(speck_ciphertext) print("The decrypted message is") print(speck_plaintext) #the decrypted message was displayed