skip to main content
Quorum
Learn
Hour of Code
Reference
Libraries
Download
Bugs
My Projects
Login
Quorum Login
Login
Cancel
Sign up for an account
"Vigenere Decryption" by Projects
This is a public project. Anyone can view it.
Vigenere Decryption
Code Area
1
boolean running = true text sample = "" text key = "" text newLine = sample:GetLineFeed() text quote = sample:GetDoubleQuote() text constants = "AZ_" integer a = constants:GetUnicodeInteger(0) integer z = constants:GetUnicodeInteger(1) integer underscore = constants:GetUnicodeInteger(2) repeat while running boolean checking = true repeat while checking checking = false sample = input("Enter an encrypted text message to decrypt (leave blank to exit)." + newLine + newLine + "Spaces will be changed to underscores, and lowercase letters will be replaced with uppercase letters. Non-alpha, non-space, and non-underscore characters will result in an error.") sample = sample:ToUpperCase() check integer counter = 0 repeat while counter < sample:GetSize() if sample:GetCharacter(counter) = " " if counter + 1 < sample:GetSize() sample = sample:GetSubtext(0, counter) + "_" + sample:GetSubtext(counter + 1) else sample = sample:GetSubtext(0, counter) + "_" end elseif not (sample:GetUnicodeInteger(counter) >= a) and (sample:GetUnicodeInteger(counter) <= z) alert("") end counter = counter + 1 end detect error text temp = input("Error: the encrypted message cannot have characters other than alpha characters, underscores, or spaces.") checking = true end end if sample:IsEmpty() running = false else checking = true repeat while checking checking = false key = input("Enter the secret key." + newLine + newLine + "Once again, spaces will be changed to underscores, and lowercase letters will be replaced with uppercase letters. Non-alpha, non-space, and non-underscore characters will result in an error.") key = key:ToUpperCase() check integer counter = 0 if key:IsEmpty() alert("") end repeat while counter < key:GetSize() if key:GetCharacter(counter) = " " if counter + 1 < key:GetSize() key = key:GetSubtext(0, counter) + "_" + key:GetSubtext(counter + 1) else key = key:GetSubtext(0, counter) + "_" end elseif not (key:GetUnicodeInteger(counter) >= a) and (key:GetUnicodeInteger(counter) <= z) alert("") end counter = counter + 1 end detect error text temp = input("Error: the key cannot have characters other than alpha characters, underscores, or spaces. The key also cannot be empty.") checking = true end end integer counter = 0 text finalSample = "" repeat while counter < sample:GetSize() integer offset = 0 if key:GetUnicodeInteger(counter mod key:GetSize()) = underscore offset = z + 1 else offset = key:GetUnicodeInteger(counter mod key:GetSize()) end integer currentSample = 0 if sample:GetUnicodeInteger(counter) = underscore currentSample = z + 1 else currentSample = sample:GetUnicodeInteger(counter) end integer newSample = 0 if offset <= currentSample newSample = a + (currentSample - offset) else newSample = a + (27 - (offset - currentSample)) end if newSample = z + 1 newSample = underscore end finalSample = finalSample + finalSample:GetUnicodeValue(newSample) counter = counter + 1 end output("Key: " + key + newLine + "Ciphertext: " + sample + newLine + "Plaintext: " + finalSample + newLine + newLine) text temp = input("The decrypted text message is as follows:" + newLine + newLine + finalSample) end end
Build (CTRL+B)
Run (CTRL+R)
Stop Program
Save this Project
Project Name:
Save Project
Cancel
Load a Project
Load Project
Cancel
Save
Load
Embed
Output Area