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
"Public Cryptography" by Projects
This is a public project. Anyone can view it.
Public Cryptography
Code Area
1
use Libraries.Compute.Math use Libraries.Containers.Array text newLine = "" newLine = newLine:GetLineFeed() integer modValue = 43 boolean checking = true text publicMod = input("Alice, Bob, and Eve" + newLine + newLine + "To simplify the program, we'll only use a public modulus value of 43." + newLine + newLine + "For the next step, only Alice should be in view of the screen.") Array
array array:Add(2) array:Add(3) array:Add(4) array:Add(5) array:Add(6) array:Add(7) array:Add(8) array:Add(9) array:Add(10) array:Add(12) array:Add(14) array:Add(15) array:Add(16) array:Add(17) array:Add(19) array:Add(20) array:Add(21) array:Add(25) array:Add(30) array:Add(32) checking = true integer alicePrivate = 0 repeat while checking check checking = false text privateKey = input("Alice" + newLine + newLine + "Input a private key value from the following list:" + newLine + newLine + "2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 17, 19, 20, 21, 25, 30, 32") alicePrivate = cast(integer, privateKey) integer counter = 0 boolean inList = false repeat while counter < array:GetSize() if alicePrivate = array:Get(counter) inList = true counter = array:GetSize() end counter = counter + 1 end if not inList alert("") end detect error text temp = input("Error: You must provide an integer from the list") checking = true end end integer alicePublic = 0 repeat while (alicePublic * alicePrivate) mod modValue not= 1 alicePublic = alicePublic + 1 end text temp = input("Alice" + newLine + newLine + "Your computed public key value is " + alicePublic + ".") temp = input("Alice, Bob, and Eve" + newLine + newLine + "The public modulus is " + modValue + "." + newLine + "Alice's public key is " + alicePublic + "." + newLine + newLine + "For the next step, only Bob should be in view of the screen.") checking = true integer bobPrivate = 0 repeat while checking check checking = false text privateKey = input("Bob" + newLine + newLine + "Input a secret number to send Alice. This number should be less than the public modulus value of " + modValue + ":") bobPrivate = cast(integer, privateKey) if bobPrivate >= modValue alert("") end detect error temp = input("Error: You must provide an integer that is less than the public modulus value.") checking = true end end integer bobPublic = (alicePublic * bobPrivate) mod modValue temp = input("Bob" + newLine + newLine + "Your computed public number is " + bobPublic + "." + newLine + newLine + "(" + alicePublic + " x " + bobPrivate + ") MOD " + modValue + " = " + bobPublic) temp = input("Alice, Bob, and Eve" + newLine + newLine + "The public modulus is " + modValue + "." + newLine + "Alice's public key is " + alicePublic + "." + newLine + "Bob's public number is " + bobPublic + "." + newLine + newLine + "For the next step, only Alice should be in view of the screen.") integer secretNum = (bobPublic * alicePrivate) mod modValue temp = input("Alice" + newLine + newLine + "Bob's secret number is " + secretNum + "." + "(" + bobPublic + " x " + alicePrivate + ") MOD " + modValue + " = " + secretNum) temp = input("Alice, Bob, and Eve" + newLine + newLine + "Alice has now received Bob's secret number." + newLine + newLine + "Can Eve crack Alice's private key?" + newLine + newLine + "(" + alicePublic + " x ??) MOD " + modValue + " = 1" + newLine + newLine + "Can Eve crack Bob's secret number?" + newLine + newLine + "(" + alicePublic + " x ??) MOD " + modValue + " = " + bobPublic)
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