SPECKSPECK is an Ultra-Lightweight Block Cipher with 32-bit blocks (64-bit key and 32 rounds) or 64-bit blocks (128-bit key and 44 rounds). It has key sizes of 64, 72, 96, 128, 144, 192 or 256 bits, and block sizes of 32, 48, 64, 96 or 128 bits. It is optimized for performance in software implementations. |
Code
The following shows a Python version of the code [here]:/p>
import speck import binascii import sys mess='hello' k='0x1b1a1918131211100b0a090803020100' def getBinary(word): return int(binascii.hexlify(word), 16) if (len(sys.argv)>1): mess=str(sys.argv[1]) m=getBinary(mess) if (len(sys.argv)>2): k=str(sys.argv[2]) key=int(k,16) print ("Message:\t",mess) print ("Key:\t\t",k) ksize=(len(k)-2)*4 bsize=32 if (ksize==72): bsize=48 if (ksize==96): bsize=48 if (ksize==128): bsize=64 print ("Key size:\t",ksize) print ("Block size:\t",bsize) w = speck.SpeckCipher(key, key_size=ksize, block_size=bsize) t = w.encrypt(int.from_bytes(mess.encode(), byteorder='big')) print ("Encrypted:\t",hex(t)) res = w.decrypt(t) hexstr= hex(res) print ("Decrypt:\t",hexstr) res_str=bytes.fromhex(hexstr[2:]).decode('utf-8') print ("Decrypt:\t",res_str)