for i in word:
c = ord(i) - int(key)
if c < 97:
c = c + 26
b = chr(c)
text += b
Is there another way to replace this without ord() and chr()?
Thank you very much!
for i in word:
c = ord(i) - int(key)
if c < 97:
c = c + 26
b = chr(c)
text += b
Is there another way to replace this without ord() and chr()?
Thank you very much!
Copyright © 2021 Jogjafile Inc.
Here is a code using numpy module plus UTF-32 encoding/decoding. This code will be very fast for large data, and needs no Python loops.
numpy
module is easily installed usingpython -m pip install numpy
. If you need solution without numpy, using plain Python, and running speed is not an issue, tell me and I'll rewrite, but in plain Python code will work much slower on big data.You can also run this code online here.
And similar slower next solution but without
numpy
, using just standard Python's built-in modulestruct
. You can also run next code online.Another solution below without using any module. Run next code online.
If text symbols are only from ASCII set then code can be simplified even further (run this code online):
One more solution for the case of ASCII chars, using two tables (run this code online)
Previous code can be extended from ASCII to wider char set (e.g. 16-bit) by replacing next line (run this code online):