Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
crypto/rsa-1 (#28)
Browse files Browse the repository at this point in the history
* rsa 1

* yaml fixes

* final yaml tweak

---------

Co-authored-by: mud-ali <[email protected]>
  • Loading branch information
Jack-Crowley and mud-ali authored Aug 25, 2023
1 parent 0ab1a14 commit 4a2ea46
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
20 changes: 20 additions & 0 deletions intro-rsa-1/chall.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Intro To RSA I
categories:
- crypto
value: 125
flag: camp{Y0u_Got_THE_fLAg_FRom_jUSt_numbeRS}
description: |-
I found this document that has some leftover numbers, can you do anything with them?
(Note) For RSA you need the message represented as a number, which varies depending on usage.
For this case, a hex string was created by linking the ascii values of the letters in hex
together, and then converting the large hex number into base 10.
hints:
- What is RSA?
- Why is it important to keep `p` and `q` secret?
files:
- src: ./info.txt
dest: rsa1.txt
authors:
- Jack Crowley
visible: true
14 changes: 14 additions & 0 deletions intro-rsa-1/crypto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
p=9431879136934316587737007754051353666702170335843
q=486822630482432419113792900499540513680992433274933
n=p*q
z=(p-1)*(q-1)
e=65537
d=pow(e, -1, z)
m = int("63616d707b5930755f476f745f5448455f664c41675f46526f6d5f6a5553745f6e756d626552537d", 16)
print("Original message (m):", m)

c = pow(m, e, n)
print("Encrypted message (c):", c)

m2 = pow(c, d, n)
print("Decrypted message (m2):", m2)
5 changes: 5 additions & 0 deletions intro-rsa-1/genM.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flag = "camp{Y0u_Got_THE_fLAg_FRom_jUSt_numbeRS}"

out = "".join([f"{ord(i):2x}" for i in flag])

print(out)
4 changes: 4 additions & 0 deletions intro-rsa-1/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p=9431879136934316587737007754051353666702170335843
q=486822630482432419113792900499540513680992433274933
e=65537
C=1794044813198073049655008313521471775955137563708224044636963525704637113279379918424880312944761851
11 changes: 11 additions & 0 deletions intro-rsa-1/solve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Intro To RSA 1

RSA is a popular type of asymmetric encryption algorithm used in cryptology. Public keys are used for encryption, and the private keys are used for decryption.

In this case, we have the 2 private keys, `p` and `q`, as well as one of the public keys `e`, and the ciphertext `c`.

To use decryption, you need private key exponent `d`, and to calculate this, you take the modular multiplicative inverse of `e`, and mod it by `(p-1)(q-1)`.

Once you have `d`, the decryption is simple. All you need to do is take `c` or the cipher text, and raise it to the `d` power, modded by `p*q`.

Once you do this, you will get the number as a integer in base 10. However, as noted in the challenge description, the message is turned into hex and then into an int, so to get the plaintext, you have to convert it into hex, and the convert it into text from there.

0 comments on commit 4a2ea46

Please sign in to comment.