GRSA is a simple implementation of RSA Key Generation in greyscript for the game Grey Hack. Comes with included encryption and decryption functions.
To install, first copy the code of grsa.src file found here and paste it into an open Code Editor process in-game. Afterwards, you must save this to /bin
as grsa
(or optionally any path and name you will later rememeber) making sure to enable Allow import. Once you have done this, you may not utilize import_code("/bin/grsa")
or if you hadn't saved it as recommended then import_code("(path-to-file)"
at the top of any file that you wish to use GRSA in.
Optionally, you can simply copy the code of grsa.src file found here and paste it at the top of any file you wish to use GRSA in.
Primary usage utilizes three functions in the grsa.src
file with two additional functions for secondary usage.
The first function you must utilize is the genKeyPair()
function which takes an argument primeLength
which dictates how many digits long the prime numbers p
and q
are. This function will return a type List where the first element is the publickey
and the second element is the privatekey
. Do note that the larger the primeLength
value, the longer it will take to generate the keys.
Afterwards, you will primarily utilize fullencrypt()
and fulldecrypt()
functions. The encryption function takes in the arguments of text
and publickey
and will return the given text encrypted using the publickey. The decryption function takes in the arguments of text
and privatekey
and will return the given text decrypted using the privatekey.
Optionally, if you do not want the characters of the encrypted text to be returned, you can utilize the encrypt()
function which takes the same arguments of the fullencrypt()
function but will return the unicode representations of the encrypted text instead of the characters. You can also optionally utilize the decrypt()
function which takes the list of unicode numbers from the encrypt()
function instead as an argument (nums
) along with the privatekey
and will return the decrypted text.
Below are examples of the functions in use:
Keys = genKeyPair(4)
puk = Keys[0]
pik = Keys[1]
text = "This is sample text."
encryptedText = fullencrypt(text, puk)
print(encryptedText) // Will print off the encrypted text.
decryptedText = fulldecrypt(encryptedText, pik)
print(decryptedText) // Will print off the decrypted text which should be the same as the original text.
Keys = genKeyPair(4)
puk = Keys[0]
pik = Keys[1]
text = "This is sample text."
encryptedText = encrypt(text, puk)
print(encryptedText) // Will print off the unicode values of the encrypted text
decryptedText = decrypt(encryptedText, pik)
print(decryptedText) // Will print off the decrypted text which should be the same as the original text.
Note that functions may be added, removed, changed, or even renamed in future updates. Functions may also have their functionality changed in future updates by request or if it seems to work better another way. You may utilize the Discussions tab to request changes or additions and the Issues tab to report issues/bugs you find.