Closed LuminousLizard closed 3 years ago
Hi, @LuminousLizard, thanks for the PR! I think it would be useful, but it breaks down on Python 2.7. Yeah, I'm still supporting it.
[...] but it breaks down on Python 2.7. [...]
I never worked with Python2 but I think it's because line 28 und 46 with ceil(len(text) / key)
.. right ?!
In Python3 ceil(16 / 5) = 4
<- the desired result
In Python2 ceil(16 / 5) = 3
I'm looking for a solution
I get the following on Python 2.7:
ciphers/scytale.py", line 29, in __enc
for block_count in range(0, ceil(len(text) / key)):
TypeError: range() integer end argument expected, got float.
Also when I execute the code(Python 3) with key = 4
from secretpy import Scytale, CryptMachine
from secretpy import alphabets
def encdec(machine, plaintext):
print(plaintext)
enc = machine.encrypt(plaintext)
print(enc)
print(machine.decrypt(enc))
print("-------------------------------")
key = 4
cm = CryptMachine(Scytale(), key)
plaintext = "I am hurt very badly help".replace(' ', '').lower()
encdec(cm, plaintext)
I'm getting not the same result from wiki ("iryyatbhmvaehedlurlp"):
iamhurtverybadlyhelp
iueaharrdemtyllhvbyp
iamhurtverybadlyhelp
-------------------------------
ciphers/scytale.py", line 29, in __enc for block_count in range(0, ceil(len(text) / key)): TypeError: range() integer end argument expected, got float.
Because e.g.: in python2 => "floor(16/5) = 3.0" in python3 => "floor(16/5) = 3"
I added an explicit conversion to int to fix it. I tested it with python2.7 and python3.9 and it works.
I'm looking for the wrong result ....
in python2 => "floor(16/5) = 3.0"
in python3 => "floor(16/5) = 3"
There is an operator //
:
16 // 5 = 3
Contains mistakes
@LuminousLizard, that's not a problem. I suppose you can fix it. I will add your code after that.
I wrote a algorithm for the Scytale Cipher if you want to use it for your package. Maybe the algorithm can be written shorter/prettier because I'm a programming novice .... but it works.
LuminousLizard