https://github.com/mjvl/csci-462-tools
Collection of miscellaneous scripts written to help for CSCI-462 - RIT's cryptography course.
https://github.com/mjvl/csci-462-tools
cryptography csci-462 diffie-hellman dsa elgamal elgamal-digital-signature rit-cryptography-course rit-csci-462 square-and-multiply
Last synced: 7 months ago
JSON representation
Collection of miscellaneous scripts written to help for CSCI-462 - RIT's cryptography course.
- Host: GitHub
- URL: https://github.com/mjvl/csci-462-tools
- Owner: MJVL
- License: gpl-3.0
- Created: 2020-10-03T03:57:28.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-04T01:52:09.000Z (almost 5 years ago)
- Last Synced: 2025-01-16T17:01:42.286Z (9 months ago)
- Topics: cryptography, csci-462, diffie-hellman, dsa, elgamal, elgamal-digital-signature, rit-cryptography-course, rit-csci-462, square-and-multiply
- Language: Python
- Homepage:
- Size: 79.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CSCI-462-Tools
Collection of miscellaneous scripts written to help for CSCI-462 - RIT's cryptography course.
Most of these scripts are built for convenience, not efficient run times/memory usage, hence the code style won't be pristine.
## Installation
```
sudo python3 setup.py install
```## Script Glossary
- [square-and-multiply](#square-and-multiply)
- [Usage](#usage)
- [Examples](#examples)
- [dhke](#dhke)
- [Usage](#usage-1)
- [Examples](#examples-1)
- [elgamal-digital-signature](#elgamal-digital-signature)
- [Usage](#usage-2)
- [Examples](#examples-2)
- [dsa](#dsa)
- [Usage](#usage-3)
- [Examples](#examples-3)
- [caesar-shift-cipher](#caesar-shift-cipher)
- [Usage](#usage-4)
- [Examples](#examples-4)
- [irreducible-polynomials](#irreducible-polynomials)
- [Usage](#usage-5)
- [Example](#example)## square-and-multiply
### Usage
```
usage: square-and-multiply [-h] [-s] base exponent modulusImplementation of the square-and-multiply algorithm, a fast method of modular
exponentiation.positional arguments:
base the base to convert to binary
exponent the exponent
modulus the modulusoptional arguments:
-h, --help show this help message and exit
-s, --show-steps show each step in the algorithm
```### Examples
```
square-and-multiply 3 197 1013^197 mod 101 = 15
``````
square-and-multiply 2 79 101 -s+-------------------------------------------------+
| Work for 2^79 mod 101 = 42 |
+--------------+----------+-------------+---------+
| Binary Digit | Work | Operation | mod 101 |
+--------------+----------+-------------+---------+
| 1 | 2 | N/A | 2 |
| 0 | 2^2 | SQ | 4 |
| 0 | 4^2 | SQ | 16 |
| 1 | 16^2 * 2 | SQ and Mult | 7 |
| 1 | 7^2 * 2 | SQ and Mult | 98 |
| 1 | 98^2 * 2 | SQ and Mult | 18 |
| 1 | 18^2 * 2 | SQ and Mult | 42 |
+--------------+----------+-------------+---------+
```## dhke
### Usage
```
usage: dhke [-h] [-s] p α sec_a sec_bWalks through the Diffie-Hellman Key Exchange setup process.
positional arguments:
p large prime p
α integer α ∈ {2, 3, ..., p - 2}
sec_a secret integer exponent a
sec_b secret integer exponent boptional arguments:
-h, --help show this help message and exit
-s, --show_steps show intermediate calculations and equations
```### Examples
```
dhke 306 5 7 17Domain Parameters (p, α) = (306, 5)
Private Keys (a, b) = (7, 17)
Public Keys (A, B) = (95, 209)
Session Key (AB) = 299
``````
dhke 29 2 5 12 -sDomain Parameters (p, α) = (29, 2)
Private Keys (a, b) = (5, 12)
A = α^a mod p
3 = 2^5 mod 29B = α^b mod p
7 = 2^12 mod 29Public Keys (A, B) = (3, 7)
AB = A^b mod p
16 = 3^12 mod 29AB = B^a mod p
16 = 7^5 mod 29AB = α^ab mod p
16 = 2^(5 * 12) mod 29Session Key (AB) = 16
```## elgamal-digital-signature
### Usage
```
usage: elgamal-digital-signature [-h] [-s] d p α x kEWalks through the Elgamal Digital Signature process and checks if the
signature is valid.positional arguments:
d the private key, a random integer d ∈ {2, 3, ..., p - 2}
p large prime p
α primitive root α
x message
kE random ephemeral key kE ∈ {0, 1, 2,.., p − 2} such that
gcd(kE, p − 1) = 1optional arguments:
-h, --help show this help message and exit
-s, --show_steps show intermediate calculations and equations
```### Examples
```
elgamal-digital-signature 67 97 23 85 77Public Key (p, α, β) = (97, 23, 15)
Elgamal Signature (x, (r, s)) = (85, (84, 29))
Verification (t, α^x) = (83, 83)
Valid Signature
``````
elgamal-digital-signature 12 29 2 26 5 -sChoose d = 12
Choose p = 29
Choose α = 2β = α^d mod p:
7 = 2^12 mod 29Public Key (p, α, β) = (29, 2, 7)
Choose x = 26
Choose kE = 5r = α^kE mod p - 1:
3 = 2^5 mod 28s = (x - dr)kE^-1 mod p - 1:
26 = (26 - (12 * 3)) * 17 mod 28Elgamal Signature (x, (r, s)) = (26, (3, 26))
t = β^r * r^s mod p:
22 = 7^3 * 3^26 mod 29α^x mod p:
22 = 2^26 mod 29Verification (t, α^x) = (22, 22)
Valid Signature
```## dsa
### Usage
```
usage: dsa [-h] [-s] p q α d hx kEWalks through the Digital Signature Algorithm process and checks if the
signature is valid.positional arguments:
p prime p
q divisor of p - 1
α element with ord(α) = q
d the private key with 0 < d < q
h(x) the hash of the message x
kE random ephemeral key with 0 < kE < qoptional arguments:
-h, --help show this help message and exit
-s, --show_steps show intermediate calculations and equations
```### Examples
```
dsa 59 29 3 7 17 25Public Key (p, q, α, β) = (59, 29, 3, 4)
DSA Signature (h(x), (r, s)) = (17, (22, 8))
Verification (v, r mod q) = (22, 22)
Valid Signature
``````
dsa 59 29 3 7 26 10 -sChoose d = 7
Choose p = 59
Choose q = 29
Choose α = 3β = α^d mod p:
4 = 3^7 mod 59Public Key (p, q, α, β) = (59, 29, 3, 4)
Compute h(x) = 26
Choose kE = 10r = (α^kE mod p) mod q
20 = (3^10 mod 59) mod 29s = (h(x) + dr)kE^-1 mod q
5 = (26 - (7 * 20)) * 3 mod 29DSA Signature (h(x), (r, s)) = (26, (20, 5))
w = s^-1 mod q
6 = 5^-1 mod 29u1 = w * h(x) mod q
11 = 6 * 26 mod 29u2 = w * r mod q
4 = 6 * 20 mod 29v = (α^u1 * β^u2 mod p) mod q
20 = (3^11 * 4^4 mod 59) mod 29`Verification (v, r mod q) = (20, 20)
Valid Signature
```## caesar-shift-cipher
### Usage
```
usage: caesar-shift-cipher [-h] [-k KEY] textImplements basic ASCII encryption/decryption through a Ceasar cipher, as well
as brute forcing.positional arguments:
text the plaintext or ciphertext to encrypt or decrypt
respectivelyoptional arguments:
-h, --help show this help message and exit
-k KEY, --key KEY the shift (if known, no value = brute force)
```### Examples
```
caesar-shift-cipher xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpitghlxiwiwtxgqadds -k 11Shifted: ifweallunitewewillcausetheriverstostainthegreatwaterswiththeirblood
``````
caesar-shift-cipher "freq analysis"+-------+---------------+
| Shift | Text |
+-------+---------------+
| 0 | freq analysis |
| 1 | gsfr bobmztjt |
| 2 | htgs cpcnauku |
| 3 | iuht dqdobvlv |
| 4 | jviu erepcwmw |
| 5 | kwjv fsfqdxnx |
| 6 | lxkw gtgreyoy |
| 7 | mylx huhsfzpz |
| 8 | nzmy ivitgaqa |
| 9 | oanz jwjuhbrb |
| 10 | pboa kxkvicsc |
| 11 | qcpb lylwjdtd |
| 12 | rdqc mzmxkeue |
| 13 | serd nanylfvf |
| 14 | tfse obozmgwg |
| 15 | ugtf pcpanhxh |
| 16 | vhug qdqboiyi |
| 17 | wivh rercpjzj |
| 18 | xjwi sfsdqkak |
| 19 | ykxj tgterlbl |
| 20 | zlyk uhufsmcm |
| 21 | amzl vivgtndn |
| 22 | bnam wjwhuoeo |
| 23 | cobn xkxivpfp |
| 24 | dpco ylyjwqgq |
| 25 | eqdp zmzkxrhr |
+-------+---------------+
```## irreducible-polynomials
### Usage
```
usage: irreducible-polynomials [-h] [-r] degreeFinds all irreducible (and optionally reducible) polynomials up to a specified
degree in Z2.positional arguments:
degree degree to find irreducible polynomials up tooptional arguments:
-h, --help show this help message and exit
-r, --reducible include reducible polynomials
```### Example
```
irreducible-polynomials 2 -rPolynomials up to Degree 2 in Z2
---------------------
Reducible Polynomials
---------------------
x^2
x^2 + 1
x^2 + x
-----------------------
Irreducible Polynomials
-----------------------
x
x + 1
x^2 + x + 1
```