Created
September 18, 2019 19:06
-
-
Save JohnnyJayJay/1334ef8586e4c3aa8518973320fcde84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extended_euclidian(a, b): | |
if b == 0: | |
return a, 1, 0 | |
gcd, s, t = extended_euclidian(b, a % b) | |
s, t = t, s - int(a / b) * t | |
return gcd, s, t | |
print("Alphabet length:") | |
length = int(input()) | |
print("Key:") | |
key = int(input()) | |
gcd, _, inverse = extended_euclidian(length, key) | |
if gcd != 1: | |
print("Alphabet length/key combination is ambiguous, could not determine inverse key") | |
else: | |
print(f'Inverse key: {inverse}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment