Values to use for Supplement to PS 5
Math 202 Cryptography
October 10, 2018

T. Ratliff, Wheaton College
ratliff_thomas@wheatoncollege.edu

Converting strings to/from hex

stringTohexstring[str] will convert a 16-character string x to a 32-digit hexadecimal string representing the ASCII encoding of x
hexstringTostring[str] performs the opposite conversion

stringTohexstring[str_]:= Module[ {total,i,list},
If[StringLength[str]≠16, Return["** ERROR ** String must be exactly 16 characters long"]];
Return[IntegerString[Total[Flatten[Table[ToCharacterCode[StringTake[str,{i+1}]]*16^(2*(15-i)),{i,0,15}]]],16]
]];

hexstringTostring[h_]:=Module[{i},
Return[FromCharacterCode[Table[FromDigits[StringTake[h,{2i+1,2i+2}],16],{i,0,15}]]]
]

The stringTohexstring[ ] function will complain if your string is not the right length

stringTohexstring["This string is too long since it has more than 16 characters"]

stringTohexstring["Too short"]

stringTohexstring["Just right      "]

The hexstringTostring[ ] will convert a string of hex values to the corresponding ASCII characters

hexstringTostring["4a757374207269676874202020202020"]

A few more handy commands

To convert a number from base 10 to hexadecimal, use BaseForm[num, 16]

BaseForm[12347,16]

To convert from hexadecimal to decimal, use 16^^hexform

16^^303B

Mathematica can have trouble raising values to extremely large powers

Mod[3^1342085708390975109345287578495972988491230987651094, 16]

But the PowerMod[num, exp, mod] can handle it by using the Square and Multiply algorithm (I believe)
This will be helpful in decryption for RSA

PowerMod[3,1342085708390975109345287578495972988491230987651094, 16]

The values for p, q, and e used in Problem 1

p=
q=
e=2^16 + 1

The values for (Subscript[k, pub])=(n,e) to use in Problem 2

n =
e=2^16+1