Skip to content

Commit 8c4a9cc

Browse files
committed
assignment 6
1 parent f14d306 commit 8c4a9cc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

ramp.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
import codecs
4+
import string
5+
import sys
6+
import time
7+
8+
from cryptography.hazmat.backends import default_backend
9+
from cryptography.hazmat.primitives.hashes import SHA1
10+
from cryptography.hazmat.primitives.twofactor.totp import TOTP
11+
12+
13+
ONE_WEEK_IN_SECONDS = 604_800
14+
15+
16+
def generate_secret():
17+
totp = TOTP(
18+
key=codecs.encode(string.ascii_letters, encoding="utf-8"),
19+
length=8,
20+
algorithm=SHA1(),
21+
time_step=ONE_WEEK_IN_SECONDS,
22+
backend=default_backend(),
23+
)
24+
seed = int(time.time())
25+
token = codecs.decode(totp.generate(seed), encoding="utf-8")
26+
return f"{token}-{seed}"
27+
28+
29+
if __name__ == "__main__":
30+
sys.stdout.write(
31+
f"Please head to https://ramp.com/careers and use this secret when "
32+
f"you apply: {generate_secret()}\n"
33+
)
34+
35+

0 commit comments

Comments
 (0)