0
$\begingroup$
     RSAcrack[cipher, n, e]
        
        ClearAll["`*"]
        
        p = 12131072439211271897323671531612440428472427633701410925634549312301964373042085619324197365322416866541017057361365214171711713797974299334871062829803541; 
        
        q = 12027524255478748885956220793734512128733387803682075433653899983955179850988797899869146900809131611153346817050832096022160146366346391812470987105415233; 
        
        n = p*q;
        
        e = 65537; 
        
        [Phi] = (p - 1)*(q - 1);
        
        d = PowerMod[e, -1, [Phi]];
        
        message1 = 
          "Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. Edsger Dijkstra"; 
        
        c = ascii = ToCharacterCode[message1]
        
        c = Row[DeleteCases[
           First[Row[{83, 105, 109, 112, 108, 105, 99, 105, 116, 121, 32, 105, 115, 
              32, 97, 32, 103, 114, 101, 97, 116, 32, 118, 105, 114, 116, 117, 101, 
              32, 98, 117, 116, 32, 105, 116, 32, 114, 101, 113, 117, 105, 114, 101, 
              115, 32, 104, 97, 114, 100, 32, 119, 111, 114, 107, 32, 116, 111, 32, 
              97, 99, 104, 105, 101, 118, 101, 32, 105, 116, 32, 97, 110, 100, 32, 
              101, 100, 117, 99, 97, 116, 105, 111, 110, 32, 116, 111, 32, 97, 112, 
              112, 114, 101, 99, 105, 97, 116, 101, 32, 105, 116, 46, 32, 65, 110, 
              100, 32, 116, 111, 32, 109, 97, 107, 101, 32, 109, 97, 116, 116, 101, 
              114, 115, 32, 119, 111, 114, 115, 101, 58, 32, 99, 111, 109, 112, 108, 
              101, 120, 105, 116, 121, 32, 115, 101, 108, 108, 115, 32, 98, 101, 116, 
              116, 101, 114, 46, 32, 69, 100, 115, 103, 101, 114, 32, 68, 105, 106, 
              107, 115, 116, 114, 97}]], ","]]
c^e mod n

This is what i have so far. I get the ascii numbers from the output of the last line in the code. But i want them in a matrix table so that I can send it away for someone to try an decrypt it. How do I do this?

$\endgroup$
1
  • 1
    $\begingroup$ Why are you using Row? This is for presentation purposes and should not be involved in computations. Your code is messy and missing details - you have mistakes too: [Phi] which should be \[Phi], and c^e mod n at the end which is not Mathematica syntax. Could you please clarify what you mean by matrix table. If you want your output in a grid, maybe you should provide a nested list to Grid. Also your DeleteCases is wrong - you're deleting the string ",". $\endgroup$
    – flinty
    Oct 1, 2021 at 15:56

1 Answer 1

1
$\begingroup$

toNumbers here is the inverse of toText. I've written the output to a text file - one number per line. It's up to you how big you want to make the chunks - I've chosen 32 bytes.

message1 = "Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. Edsger Dijkstra";

p = 12131072439211271897323671531612440428472427633701410925634549312301964373042085619324197365322416866541017057361365214171711713797974299334871062829803541;
q = 12027524255478748885956220793734512128733387803682075433653899983955179850988797899869146900809131611153346817050832096022160146366346391812470987105415233;
n = p*q;
e = 65537;

toText[numbers_] := StringJoin[
   FromCharacterCode[Reverse[IntegerDigits[#, 256]]] & /@ numbers];

toNumbers[text_, chunksize_] := 
 FromDigits[Reverse[#], 256] & /@ 
  Partition[ToCharacterCode@text, chunksize, chunksize, 1, 0]

ciphertext = PowerMod[toNumbers[message1, 32], e, n];
Export["ciphertext.txt", ciphertext]
37246423807947804842303396620313731332121100158526755958591270381921821200458849438334437481325903271103670394003399485924896799836133289482148132495808352652521492077384268056065417706138911806850949604339919310879586464998455667688887884799103770164760299295591292811032262366452580494949621860046894120030
70625283227481498188191129068432470280389507710975765530625636306629406992249893658081346464754951288622031801261462708714942932463422405804249043642616400465108126650506716369126389321179430134194630983661284444641219318650438600976259008086169010383063245958663150467019394143347513421913514262795956900326
69193040614674370771279136586290811484959747212510764149474224457457117760633019819590383820089391127672214757945673658671942041928148037773805198082904847727592965786606295052310814318074907746263161921038887882458662053556170921518587922089350195877645575370737266204943511031597320490738114282866598686146
139659124044241300833008452280274773364472223961785761319098615162095354806546897092844698150020302950189327150084814454507977090281110771089154927255330443365883973102772154939594044347426180486440481093611659652606342321810555350178453257265958614016184673151673943824136839351382663543448590193217691590170
45084933859438049317995247663370346600069031101678449928741859562991158083652666484771875097020895838496359490065446688642591554649883000884126912601223864961407212286873848399558621079663086487894619964782044024441923197202556949461758009411580167812314933637885252956724014641896027174625863187653559519578
61947261742093059553288143490615730151334985968370112798904868618984604055014947478543528097768012312325575412564953725928693527265984268519403312565204692522991752661230021085702257900016523807934240195970554536689610698706268509180351060600262169696545183009729489331843274002372097874647155885408677408433
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.