Skip to content

Instantly share code, notes, and snippets.

@JohnnyJayJay
Created September 18, 2019 19:06
Show Gist options
  • Save JohnnyJayJay/1334ef8586e4c3aa8518973320fcde84 to your computer and use it in GitHub Desktop.
Save JohnnyJayJay/1334ef8586e4c3aa8518973320fcde84 to your computer and use it in GitHub Desktop.
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