Skip to content

Instantly share code, notes, and snippets.

@enedil
Created May 14, 2019 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enedil/d32d185519655c16f52a8396e2eecdf4 to your computer and use it in GitHub Desktop.
Save enedil/d32d185519655c16f52a8396e2eecdf4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import cgi
from secret import N, e, d
def encrypt(m):
return pow(m, e, N)
def decrypt(c):
return pow(c, d, N)
print("Content-type: text/html\n")
print( """
<html>
<head><title>Zadanie 3: RSA</title></head>
<meta charset="utf-8">
<body>
""")
print("""
<p>
Oto klucz publiczny: <br/>
N = %d <br/>
e = %d <br/>
</p>
""" % (N, e))
print("""
<p>
Kluczem tym zaszyfrowano pewną wiadomość (jest to liczba): <br/>
928066735300335970761240687353165144477163930660377590215387151172657023088092014506935678554845211540813156
</p>
""")
form = cgi.FieldStorage()
szyfrogram = form.getvalue('szyfrogram', '')
if szyfrogram:
try:
dec = decrypt(int(szyfrogram))
print("Po odszyfrowaniu, stwierdzam że odpowiadająca jemu odszyfrowana liczba jest ", end='')
if dec % 2:
print('parzysta.')
else:
print('nieparzysta.')
except Exception as e:
print("Wystąpił błąd:", e)
print(
"""<form method="post">
<p>Wprowadź szyfrogram: <input type="text" name="szyfrogram"/></p>
<input type="submit">
</form>
</body>
</html>""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment