Introduction to the experiment:
The Virginia cipher is a multi-table substitution cipher.
The difference between a multi-meter substitution code and a single-meter substitution code is:
Single table substitution plaintext and ciphertext one-to-one correspondence, multi-table substitution plaintext and ciphertext are not one-to-one correspondence, the same plaintext can be encrypted into different ciphertext.
Multi-table substitution using keys.
I: Virginia Decryption Principles
Virginia Encryption Principle
Write the plaintext "cyber great wall corporation" in the first line without spaces.
Converted to a number and written on the second line
The key "iscbupt" is transformed into the digital key "8, 18, 2, 1, 20, 15, 19".
Write to the third line and repeat until it is as long as the plain text
The digital plaintext and the digital key are summed and modulo 26 is written on the fourth line.
Convert the numbers in the fourth line into letters and write them in the fifth line to make the ciphertext.
The Virginia Declassification Principle
The first line contains the ciphertext.
Write the digital cipher on the second line.
Write the digital key on the third line
Write (digital ciphertext-digital key) on the fourth line mod 26
In the fifth line there is an explicit text
II: Virginia Matrix
Since the encryption is a digital plaintext plus a digital key for mod26, it is offset by a key distance relative to the plaintext. The matrix can be obtained
In encryption, if the key is L and the plaintext is S, then the ciphertext is D.
The value of the key letter a is 0. The digital plaintext is offset by 0.
If the value of key letter b is 1, the digital plaintext is offset by 1, and so on.
decryption matrix
Find the key, the ciphertext, and then the plaintext.
III: Encryption code implementation
Click to view code
def KeyTran(key,keyLen):
strResult=""
if(len(key)>keyLen):
strResult=key[0:keyLen]
else:
newKeyList=list()
index=0
while(index<keyLen):
(key[index%len(key)])
index+=1
strResult="".join(newKeyList)
return strResult
def PassMatrix():
pm=list()
# startIndex=65
startIndex=ord('A')
while(startIndex<91):
pmRow=list()
i=0
while(i<26):
currChr=startIndex+i
if(currChr>90):
currChr=currChr-26
(chr(currChr))
print("".join(pmRow))
(pmRow)
startIndex+=1
return pm
txtPlain=input("please input your plain text:")
txtPlain= ()
print(txtPlain)
txtKey=input("please input your key:")
txtKey=()
print(txtKey)
print("trasforming the key...")
txtNewKey=KeyTran(txtKey,len(txtPlain))
print("Constructing key password matrix:")
lsPM=PassMatrix()
print("Plain Text: ",txtPlain)
print("encryption key:",txtNewKey)
print("encrypting...")
gapPlain=0
gapKey=0
strResult=list()
index=0
for ch in txtPlain:
gapPlain=ord(ch)-ord('A')
gapKey=ord(txtNewKey[index])-ord('A')
print(ch, txtNewKey[index], "|", gapPlain, ",", gapKey, "->", lsPM[gapKey][gapPlain])
(lsPM[gapKey][gapPlain])
index+=1
print("encryption result:","".join(strResult))