Block CipherA block cipher, such as AES and DES, involves taking a number of bits in a block and then ciphering each block. DES uses 64-bit blocks while AES uses 128-bit blocks. |
Code
ASCII characters are 8 bits long. If we use a 32-bit block size, we can get 4 characters. For a 64-bit block size, we get 8 characters. The following outlines the code:
# https://asecuritysite.com/encryption/blk import sys BLOCKSIZE = 8 n=BLOCKSIZE message="hello how are you?" if (len(sys.argv)>1): message=str(sys.argv[1]) if (len(sys.argv)>2): n=int(sys.argv[2])/8 print ("Message:",message) print ("Bytes per block:",n) print ("\nBlocks ...") message = [message[i: i + n] for i in range(0, len(message), n)] lengthOfLastBlock = len(message[len(message)-1]) if ( lengthOfLastBlock < BLOCKSIZE): for i in range(lengthOfLastBlock, BLOCKSIZE): message[len(message)-1] += " " i=0 for b in message: print ('Block [',i,']',b) i=i+1