Created
July 21, 2018 18:41
-
-
Save vasa-develop/6cc6cfcfed3402e6717aa52bc811e610 to your computer and use it in GitHub Desktop.
DO NOT USE THIS CODE. THIS CODE IS USED TO DEMONSTRATE A VULNERABILITY IN A SOLIDITY CODE.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//encryption contract | |
contract Rot26Encryption { | |
event Result(string convertedString); | |
//rot13 encrypt a string | |
function rot13Encrypt (string text) public { | |
uint256 length = bytes(text).length; | |
for (var i = 0; i < length; i++) { | |
byte char = bytes(text)[i]; | |
//inline assembly to modify the string | |
assembly { | |
char := byte(0,char) // get the first byte | |
if and(gt(char,0x6D), lt(char,0x7B)) // if the character is in [n,z], i.e. wrapping. | |
{ char:= sub(0x60, sub(0x7A,char)) } // subtract from the ascii number a by the difference char is from z. | |
if iszero(eq(char, 0x20)) // ignore spaces | |
{mstore8(add(add(text,0x20), mul(i,1)), add(char,26))} // add 13 to char. | |
} | |
} | |
emit Result(text); | |
} | |
// rot13 decrypt a string | |
function rot13Decrypt (string text) public { | |
uint256 length = bytes(text).length; | |
for (var i = 0; i < length; i++) { | |
byte char = bytes(text)[i]; | |
assembly { | |
char := byte(0,char) | |
if and(gt(char,0x60), lt(char,0x6E)) | |
{ char:= add(0x7B, sub(char,0x61)) } | |
if iszero(eq(char, 0x20)) | |
{mstore8(add(add(text,0x20), mul(i,1)), sub(char,26))} | |
} | |
} | |
emit Result(text); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment