Code Monkey home page Code Monkey logo

kidrsa's Introduction

KidRSA

After watching 'How to Break Cryptography' and 'This Video was Not Encrypted with RSA' my curiosity motivated me to demystify RSA cryptography. Inspired by Neal Koblitz's article 'Cryptography As a Teaching Tool' this module was programmed following his 'Kid-RSA' example.

The beauty of this demonstration is the simplicity of arithmetic operations to encrypt and decrypt with minimal computational steps.

This demonstration (just as the article's example) explains the following two procedures:

  • How to convert plain text message into simple-substitution cipher that gets encrypted by the sender and then decrypted by the recipient. The recipient then runs, the now decrypted cipher, thru an inverse simple-substitution algorithm to retrieve the plain text message.

  • How a digital signature is created and sent.

GitHub license PS Gallery

Caveat

This is a demonstration, not suitable for production. The longer the message to encrypt, the more likely this demonstration will fail.

Instructions

To install, run the following command in PowerShell.

$ Install-Module KidRSA

Explanation

Copy-and-paste the first six lines of code into PowerShell after installing this module. Shift + Enter to paste multiple lines of code such as below. Use the Up Arrow to repeat previous command followed by an Enter and see that the generated RSA keys are different than previously. With a new generated set of (asymmetric) keys will have a different encrypted value but the ConvertTo-PlainText (simple-substitution cipher) function will output the same plain text value.

Interestingly this function will fail to retrieve the plain text value at times (roughly 1 out 15). Since Get-RSAKey function generate keys with numbers less than 1000, it limits the plain text message to be a length no greater than 5 or 4 at times. Read more on this limitation here.

$AlicesKeys = Get-RSAKey -Verbose
$PlainText = "HELLO"
$CipherText = ConvertTo-CipherText $PlainText -Verbose
$EncryptedCipherText = ConvertTo-PublicEncryptionValue -CipherText $CipherText -PublicKey $AlicesKeys.e -N $AlicesKeys.n -Verbose
$CipherText = ConvertTo-PrivateDecryptionValue -EncryptedCipherText $EncryptedCipherText -PrivateKey $AlicesKeys.d -N $AlicesKeys.n -Verbose
ConvertTo-PlainText $CipherText -Verbose
VERBOSE: The value for 'a' is: 672
VERBOSE: The value for 'b' is: 263
VERBOSE: The value for 'a_' is: 342
VERBOSE: The value for 'b_' is: 543
VERBOSE: The value of Private key 'e' (encrypt) is: 60444042
VERBOSE: The value of Public key 'd' (decrypt) is: 95967368
VERBOSE: The value of 'n' is: 32821204753
VERBOSE: Ciphertext value is : 32768720
VERBOSE: Encrypted cipher value is : 12644736949
VERBOSE: Decrypted cipher value is : 32768720
VERBOSE: PlainText value is : HELLO
HELLO
E:\>

kidrsa's People

Contributors

marckassay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

naziafakhruddin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.