SL Exp No.4
SL Exp No.4
SL Exp No.4
Aim: Design and Implement a Product cipher using Substitution ciphers and
Transposition ciphers.
Program:
def caesar_cipher(text, shift):
result = []
for char in text:
if char.isalpha():
shift_amount = shift % 26
if char.islower():
start = ord('a')
else:
start = ord('A')
result.append(chr(start + (ord(char) - start + shift_amount) % 26))
else:
result.append(char)
return ''.join(result)
# Create grid
grid = [text[i:i + num_columns] for i in range(0, len(text), num_columns)]
# Concatenate columns
return ''.join(columns)
def product_cipher(plaintext, shift, key):
# Apply Caesar Cipher (Substitution)
return encrypted_text
# Create grid
grid = ['' for _ in range(num_rows)]
for i in range(num_rows):
for j in range(num_columns):
grid[i] += columns[j][i]
# Remove padding
decrypted_text = ''.join(grid).rstrip()
def main():
plaintext = input("Enter the plaintext: ")
shift = int(input("Enter the shift for Caesar Cipher: "))
key = input("Enter the key for Columnar Transposition Cipher (e.g.,
'3412'): ")
Output:
Conclusion: