hacking-tutorial

Getting Started with Ethical Hacking

Setup for learning


Virtualization


Introduction to Penetration Testing

Connecting Wireless adapter to Kali

Wireless Modes

Enabling Monitor Mode on Wireless Adapter


Extras - Learning Section -๐Ÿ” RSA Encryption

๐Ÿ“Œ What is RSA?

RSA (named after its inventors: Rivest, Shamir, and Adleman) is one of the most famous public-key cryptosystems in the world.

It is used for:

๐Ÿ‘‰ Unlike symmetric encryption (same key for both sides), RSA uses two keys:


๐Ÿงฎ The Math Behind RSA (Step by Step)

RSAโ€™s strength comes from the fact that itโ€™s easy to multiply big primes but hard to factor them back. Letโ€™s see how the keys are built:

Step 1: Pick Two Large Primes โœจ

Choose two secret primes:
[ p, \ q ]

In the real world, these are HUGE (hundreds of digits long).


Step 2: Build the Modulus ๐Ÿ”ฒ

[ n = p \times q ]
This number ( n ) is part of both the public and private keys.


Step 3: Euler Joins the Party ๐Ÿง‘โ€๐Ÿซ

Compute Eulerโ€™s totient: [ \varphi(n) = (p-1)(q-1) ]
This is how many numbers less than ( n ) are โ€œcoprimeโ€ with it.


Step 4: Pick the Public Exponent ๐Ÿ”‘

Choose ( e ), such that: [ gcd(e, \varphi(n)) = 1 ]
In other words, ( e ) and ( \varphi(n) ) donโ€™t share factors.
Popular choices: ( e = 3 ) or ( e = 65537 ) (fast and secure).


Step 5: Find the Secret Ingredient ๐Ÿง™

Compute the private exponent ( d ) by solving: [ d \times e \equiv 1 \ (\text{mod } \varphi(n)) ]
This means ( d ) is the modular inverse of ( e ).
Finding ( d ) is easy if you know ( \varphi(n) ), but impossible without factoring ( n )!


Step 6: Keys Ready ๐ŸŽ‰


Step 7: Encryption & Decryption ๐Ÿ”

Magic: thanks to modular arithmetic, this always works!


flowchart TD

    A[๐Ÿ” Start: RSA Key Generation] --> B[โœจ Pick two large primes p & q]
    B --> C[๐Ÿ”ฒ Compute modulus n = p * q]
    C --> D[๐Ÿง‘โ€๐Ÿซ Compute Euler's totient ฯ† of n = p-1 * q-1]
    D --> E[๐Ÿ”‘ Choose public exponent e = 3 or 65537]
    E --> F[๐Ÿง™ Find private exponent d such that d * e โ‰ก 1 mod ฯ† of n]
    F --> G[๐ŸŽ‰ Keys Ready]

    G --> H1[๐ŸŒ Public Key: e , n]
    G --> H2[๐Ÿ”’ Private Key: d , n]

    H1 --> I1[๐Ÿ“ค Encryption: C = M^e mod n]
    H2 --> I2[๐Ÿ“ฅ Decryption: M = C^d mod n]

    I1 --> J[๐Ÿ”„ Message securely transmitted]
    I2 --> J

Toy Example (Small Numbers)

โš ๏ธ Donโ€™t try this at home with real secrets โ€” small numbers are too easy to crack. This is just a classroom demo.

  1. Pick primes:
    ( p = 5, q = 11 )

  2. Compute modulus:
    ( n = 5 \times 11 = 55 )

  3. Compute totient:
    ( \varphi(55) = (5-1)(11-1) = 4 \times 10 = 40 )

  4. Choose ( e = 3 ) (coprime with 40).

  5. Find ( d ): solve ( 3 \times d \equiv 1 \ (\text{mod } 40) ).
    โœจ ( d = 27 ) works because ( 3 \times 27 = 81 \equiv 1 \ (\text{mod } 40) ).

Keys:


Letโ€™s Encrypt a Message!
Say our message is ( M = 9 ).


๐Ÿšจ When Does RSA Fail?

RSA is strong in theory, but weak in practice if misused:


๐Ÿ“š Further Reading


๐ŸŽฏ Key Takeaways


Path

Next Lesson: Network Hacking: Pre-Connection Attacks