External Exam Download Resources Web Applications Games Recycle Bin

block cipher q16 public use

blockcipher_q16_publicuse.py

# block_cipher (q16 of PUBLIC USE mock exam)
pin = 7826
key_blocks = []

##################
# for random keys:
# digits = list(range(10)) #[0,1,2,3,4,5,6,7,8,9]
# import random
# for i in range(4):
#   random.shuffle(digits)
#   key_blocks.append(digits[:]) #take a copy

##################
# for exam keys:
key_blocks.append([1,3,5,7,9,2,4,6,8,0])
key_blocks.append([5,4,3,2,1,0,9,8,7,6])
key_blocks.append([2,4,6,8,0,1,3,9,5,7])
key_blocks.append([0,9,8,7,6,5,4,3,2,1])
ciphertext_symbols = (')','!','@','#','$','%','^','&','*','(')

# convert pin to list of integers:
pin_numbers = list(map(int, str(pin)))
encrypted_numbers = []
ciphertext_characters = []
for i, pin_number in enumerate(pin_numbers):
  e = key_blocks[i][pin_number] #encrypted num
  encrypted_numbers.append(e)
  ciphertext_characters.append(ciphertext_symbols[e])
  
print(ciphertext_characters)

# This encryption method (Block key with substitution):
# ADVANTAGES
# 1) more complex than Caesar since it uses two methods
# of encryption firstly a private block key known only
# to the users and secondly a simple substitution cipher
# that may or may not be public 
# 2) frequency of the letter pattern does not provide
# a big clue in deciphering the entire message 
# 3) requires less computing power than more complex methods

# DISADVANTAGES
# 1) simple structure usage
# 2) can only provide minimum security to the information
# 3) due to the nature of the cipher, an encrypted text has
# only 10 possibilities with a different and private key to all numbers

# I would recommend the Block key with substitution encryption method
# over the Caesar method. The fact that the latter is more easily deciphered
# due to the regular common key shift as opposed to the private key shared
# between users makes the Block key with substitution method only slightly
# better than the Caesar.