Beruflich Dokumente
Kultur Dokumente
2) Homophonic method: In this method, for each alphabet in plain text, one character,a
pair of characters, or triplets of characters can be replaced to generate ciphertext.
3) Jumbled method: Characters of plain text can be jumbled so that cipher text can be
generated.
Ex: For the plain text ABCDEFGHIJKLMNOPQRSTUVWXYZ,
ciphertext can be ZEBRACDFGHIJKLMNOPQSTUVWXY
4) Random replace: For each character in plain text, different units of characters can be
replaced so that cipher text can be generated.
EX: For the plain text ABCDEFGHIJKLMNOPQRSTUVWXYZ,
cipher text can be DFIMRXEMVFQCPDSIZRKEZVSQPP.
INS LAB 160117733185
Algorithm:
1. ROT13:
1.1. Start
1.2. Input given plain text, and ciphertext
1.3. Increment and decrement each character by 13 in plaintext and ciphertext
respectively
1.4. Stop
2. Homphonic :
2.1. Start
2.2. Input plaintext, ciphertext and number of char to be substituted.
2.3. Substitute respective characters and encrypt and decrypt.
2.4. Stop
3. Jumbled:
3.1. Start
3.2. Input plaintext, cipher text, and keyword to be inserted to encrypt
3.3. Plaintext characters appearing in keyword are removed and keyword is appended
in the beginning
3.4. Stop
4. Random:
4.1. Start
4.2. Input plaintext, starting encrypt number and ciphertext
4.3. The plaintext characters are switched accordingly
4.4. Stop
INS LAB 160117733185
Code:
1) Rot13 Substitution:
class Rot13:
def encrypt(self):
op=''
for i in pT:
op+=chr((ord(i)-65+13)%26+65)
print(op)
def decrypt(self):
op=''
for i in eT:
op+=chr((ord(i)-65-13+26)%26+65)
print(op)
Output:
INS LAB 160117733185
2)Homophobic Substitution:
class Homo:
def encrypt(self):
op=''
for i in pT:
j= 0
k=key
while k>0:
op+=chr((ord(i)-65+13+j)%26+65)
k-=1
j+=1
print(op)
def decrypt(self):
op=''
i=1
while i<=len(eT):
op+=chr((ord(eT[i-1])-65-13+26)%26+65)
i+=key
print(op)
Output:
INS LAB 160117733185
3) Jumbled Substitution:
arr=[]
class Jumble:
def encrypt(self):
op=keyword
pos=0
for i in pT:
if i in keyword:
arr.append(pos)
else:
op+=i
pos+=1
print(op)
def decrypt(self):
op=''
pos=0
i= len(keyword)
temp=0
while i< len(eT):
if i==len(eT)-1 and pos<len(arr):
op+=eT[i]
op+=pT[arr[pos]]
break
temp+=1
op+=eT[i]
temp+=1
i+=1
print(op)
Output:
INS LAB 160117733185
4) Random substitution :
class Rand:
def encrypt(self):
op=''
j=s
k=1
for i in pT:
op+=chr((ord(i)-65+j)%26+65)
j+=k
k+=1
print(op)
def decrypt(self):
op=''
j=s
k=1
for i in eT:
op+=chr((ord(i)-65+26-j)%26+65)
j+=k
k+=1
print(op)
Output:
Conclusion: Hence, all the cipher substitution methods are implemented doing both encryption
and decryption of the given text in python.