Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autokey broken? #2

Closed
mattbruv opened this issue May 8, 2020 · 1 comment
Closed

Autokey broken? #2

mattbruv opened this issue May 8, 2020 · 1 comment

Comments

@mattbruv
Copy link

mattbruv commented May 8, 2020

from secretpy import Autokey
from secretpy import CryptMachine
from secretpy.cmdecorators import UpperCase, SaveSpaces, NoSpaces
from secretpy import alphabets

cipher = Autokey()
key = "test"
msg = "this is a secret message"

cm = CryptMachine(cipher, key)
out = cm.encrypt(msg)

print(out)

This should work, but it doesn't for some reason... Shouldn't the autokey "key" be a string instead of an integer? It's documented as an integer.

@tigertv
Copy link
Owner

tigertv commented May 9, 2020

Hi, @mattbruv !
This doesn't work because the default alphabet doesn't have 'spaces'. If you remove all spaces in msg the code works.
Also, you can use NoSpaces, it removes spaces from message:

from secretpy import Autokey
from secretpy import CryptMachine
from secretpy.cmdecorators import UpperCase, SaveSpaces, NoSpaces
from secretpy import alphabets

cipher = Autokey()
key = "test"
msg = "this is a secret message"

cm = NoSpaces(CryptMachine(cipher, key))
out = cm.encrypt(msg)

print(out)

output:
mlalbzikmurwxovwlmkw

And if you want save the spaces in message you can use SaveSpaces:

from secretpy import Autokey
from secretpy import CryptMachine
from secretpy.cmdecorators import UpperCase, SaveSpaces, NoSpaces
from secretpy import alphabets

cipher = Autokey()
key = "test"
msg = "this is a secret message"

cm = SaveSpaces(NoSpaces(CryptMachine(cipher, key)))
out = cm.encrypt(msg)

print(out)

This returns encrypted message with spaces:
mlal bz i kmurwx ovwlmkw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants