Here is an example of how it works:
Step 1: Start with 3 prime numbers. The first 2 should be at least 600 bits, but for the purpose of this example I will use 200 bits. The 3rd one, E, is a much small prime number.
P=1140883410519441712101308447239692533460267445025643826644911Step 2: Get the product of P and Q, N. N is of course a composite number. This number here is very easy to factorize, so in actuality, you would want a much larger number.
Q=1590414661111417186713343719727926429804586929133475957467297
E=65537
[N = P*Q]Step 3: Calculate the totient of N.
N=18144777027089157444288630814623233810136 9120798594281236591088451242203923952225919 0523528489981610529038878164513975567
[F=(P-1)*(Q-1)]Step 4: Calculate the decryption key. X in the formula here is any number that will work for integer division by E. It must be discovered by trial and error.
F=18144777027089157444288630814623233810136 9120798594281236590815321435040838062344453 8356560871018345674664719044729863360
[D =(F*X+1)/E]Step 5: Display the keys. N is the same for both the public key and private key, so the real private key is D. Note that the encryption key is much shorter than the decryption key.
X=34621
D=95852774074927707993761796761077098088217 3479281647406913958621426583845591735420805 994209285068375812175827975763196353
public key={E=65537, N=18144777027089157444288630814623233810136 9120798594281236591088451242203923952225919 0523528489981610529038878164513975567}Step 6: Prepare the message. To make this simple I will only allow upper case letters and use a 0 for a space, and then interpret as a Base 36 number. It would be easy to just use the byte value instead.
private key={D=9585277407492770799376179676 1077098088217347928164740691395862142658384 5591735420805994209285068375812175827975763
196353,
N=18144777027089157444288630814623233810136 9120798594281236591088451242203923952225919 0523528489981610529038878164513975567}
MESSAGE="HELLO WORLD"Step 7: Encrypt the message. This is M to the power of E, and then returning the Modulus of the result with N.
M=63637474127610289
[Z=(M^E) mod N]Step 8: Decrypt the message. This is the same formula, with different inputs.
Z=13728116117865984092396572529148599991502 7809873508726974002483165839383589462390086 8382826983129627158084569236296982522
[A=(Z^D) mod N]Conclusion: Simple and elegant. It should be used more.
a=63637474127610289
message=hello0world
Update: Even with a 400 bit product (121 digits), my verification program can't crack this after 20 minutes. So I think this is sufficient for all practical purposes. RSA uses a 2048 bit key.
Update2: I ran the verification program again. After 36 minutes, it only had a 92% chance that the smallest factor had at least 25 digits. So I think 100 bit numbers should really be sufficient.
No comments:
Post a Comment