if you like the Diana Cryptosystem and want to use it with a foreign language, on an offline Computer, you may find my base26 Encoder/Decoder useful.
'EWJILIG'import base26
base26.encode(b'test')
b'test'base26.decode('EWJILIG')
On Fri, 19 Jan 2024 21:05:20 +0100, Stefan Claas wrote:
if you like the Diana Cryptosystem and want to use it with a foreign language, on an offline Computer, you may find my base26
Encoder/Decoder useful.
Found a Python version:
https://pypi.org/project/base26/#files
Example:
'EWJILIG'import base26
base26.encode(b'test')
b'test'base26.decode('EWJILIG')
$ echo -n 'test' | base26 MEXDLEME
I guess there is no defined standard (RFC) for base26, maybe I am wrong.
On Sat, 16 Mar 2024 14:30:45 +0100, Stefan Claas wrote:
$ echo -n 'test' | base26 MEXDLEME
I guess there is no defined standard (RFC) for base26, maybe I am
wrong.
There ought to be. But, of course, maybe none of the math heads
thinking these things through have returned with the verdict from
their round table meeting yet? ;)
Not sure what either of you guys used, but this page: https://www.dcode.fr/base-26-cipher
...claims there are two ways to start: A=0 or A=1
Maybe that?
He has a "machine" on his site you can compare things with. But it
returns the result in numeric Base26, not as encoded letters:
this here is a test
338902 126182 226 0 337135
Also, Python starts its arrays/lists with 0 for the first item where
some other languages use 1. I have no idea what "Go" (was it?) uses.
If I get a little free time I'll probably check the Python module
against that page (linked above). It was fairly short.
I've been fiddling with the HC-9 cipher that came out of that handy
little machine the Swedish military used up until around 1995-ish.
I've got some info about that coding from that site, it is very
informative. So I'm currently all "ciphered out" and I want to spend
some time with some other things for a while. :)
On Fri, 19 Jan 2024 21:05:20 +0100, Stefan Claas wrote:
if you like the Diana Cryptosystem and want to use it with a foreign language, on an offline Computer, you may find my base26 Encoder/Decoder useful.
Found a Python version:
https://pypi.org/project/base26/#files
Example:
'EWJILIG'import base26
base26.encode(b'test')
b'test'base26.decode('EWJILIG')
Cri-Cri wrote:
On Fri, 19 Jan 2024 21:05:20 +0100, Stefan Claas wrote:
if you like the Diana Cryptosystem and want to use it with a foreign language, on an offline Computer, you may find my base26 Encoder/Decoder useful.
Found a Python version:
https://pypi.org/project/base26/#files
Example:
'EWJILIG'import base26
base26.encode(b'test')
b'test'base26.decode('EWJILIG')
I now have a Rust Version, derived from the Python library and
it encodes 'test' with the same result, but when encoding with
Rust, the Python code can not decode properly, while decoding
from Python with Rust works. Oh, well ... :-(
(Wish I was a Programmer!)
$ echo -n 'AAZCESYRPSBENRDWLUQLYETYZZJCPAHHAVEIPLIONRSBHYUEHANMAUZZQCSOGOXJEBILDQVWRGD' | b26 -dimport base26
base26.encode(b'The quick brown fox jumps over the lazy dog.') 'AAZCESYRPSBENRDWLUQLYETYZZJCPAHHAVEIPLIONRSBHYUEHANMAUZZQCSOGOXJEBILDQVWRGD' >>>
b'Hello sci.crypt'import base26
base26.decode('UQZGYLNMDHTUDTGJYKJRQGDKOC')
Stefan Claas wrote:
[...]
Ok. everything is fine. :-)
Example Unicode text encoded, with -l Parameter for line-length:
SASHXTRHYGJXHJBMKMWLUPZPTINOBPKNFSPZNFBWWXLWUNFRSGZHPACWHNFRFTGR
Stefan Claas wrote:
Stefan Claas wrote:
[...]
Ok. everything is fine. :-)
Example Unicode text encoded, with -l Parameter for line-length:
SASHXTRHYGJXHJBMKMWLUPZPTINOBPKNFSPZNFBWWXLWUNFRSGZHPACWHNFRFTGR
Another example, an encrypted SMS message, done with Adiantum (FPE)
and base26 encoded and grouped in five letter groups.
JFMLM THPBQ RDZJD KTZEJ MOGKY BPCIY LTHNL FNSBA
This allows one to create SMS messages on a little offline notebook
and type it in an old mobile phone, or use, for example, Modem-Manager-GUI under Linux, to send encrypted SMS messages.
P.S. Looks now like a Diana Cryptosystem message. ;-)
Ok, I figured out that my Python3 code example is bad.
What I fail to understand in the original Base26 Python module is, why the need for the things at the top:
NOM = 851
DENOM = 500
Looks like magic numbers to me.
In this case, NOM = 851 and DENOM = 500, which means that the length of
the output is about 85.1% of the length of the input when the input is
being encoded, and about 58.8%
of the length of the input when the input is being decoded.
On Sat, 27 Apr 2024 17:31:29 +0200, Stefan Claas wrote:
In this case, NOM = 851 and DENOM = 500, which means that the length of
the output is about 85.1% of the length of the input when the input is being encoded, and about 58.8%
of the length of the input when the input is being decoded.
Yeah, magic numbers. I don't like the concept of "about" here, since there
is nothing "about" about it. ;)
I suspect the concept of "about" is what is wrong with the implementation, since it isn't the same as what you got with your code. Or both are flawed and it should be something different altogether.
Why didn't you ask your friend to write the encoder/decoder for you from scratch?
If you used this approach with your Rust code, you should be able to use
the same description to get it in whatever language you wanted.
If you use other base n encoders you will see, like in base64, base32, base58,
base85, base91 etc. the base n system relies always on letters (and some digits and special characters).
So, in the end people are free to choose which base26 approach they like to use,
because there is no standard, like an RFC, available.
Example:
$ echo -n 'Hello sci.crypt! :-)' | base16 48656c6c6f207363692e637279707421203a2d29
$ echo -n 'Hello sci.crypt! :-)' | base32
JBSWY3DPEBZWG2JOMNZHS4DUEEQDULJJ
$ echo -n 'Hello sci.crypt! :-)' | cbase32
91JPRV3F41SP6T9ECDS7JW3M44G3MB99
$ echo -n 'Hello sci.crypt! :-)' | base26 | ug -g
GNUKB WRRLQ QCISN UJYEH SKYLR PJHKG YPTEA
Hope this makes sense!
On 28.04.2024 10:12, Stefan Claas wrote:
So, in the end people are free to choose which base26 approach they like to use,
because there is no standard, like an RFC, available.
But base26 doesn't make much sense. How big are the chunks of the
data input stream you encode in base26? If you encode each byte,
you need 2 digits for the byte, which is the same as base16 (hex format).
The same is true for 2 and 3 byte chunks (4 and 6 digits). Starting
with 4 byte chunks you can save one digit (7 instead of 8 for hex).
The next step is at 7 byte chunks (12 instead of 14 digits for hex).
But this is also the biggest size which you can handle with 64 bit arithmetic. Starting with 11 byte chunks you can save 3 digits (19
instead of 22 for hex), but this already requires long number
arithmetic.
So, if you can't use base32 at least, better stay at base16 (hex format) instead of base26. There is only a small advantage in size, but a big disadvantage in computing time and you have to cope with padding if the message length is not a multiple of the chunk length.
$ echo -n 'Hello sci.crypt! :-)' | base16 48656c6c6f207363692e637279707421203a2d29
$ echo -n 'Hello sci.crypt! :-)' | base26 | ug -g
GNUKB WRRLQ QCISN UJYEH SKYLR PJHKG YPTEA
But how does your base26 coding work. Take you four bytes
of the input string and then convert this 32 bit number
to base26 resulting in a 7 digit base26 number? There
are 5 of this 4 byte chunks which gives a total of 35
base26 digits. But how do you handle padding if the
input string length is not a multiple of 4?
Or do you treat the complete string as a single number 0x48656c6c6f207363692e637279707421203a2d29 and convert
this 160 bit number to a single base26 number? This would
also result in a 35 digit base26 number, but would
require long number arithmetic and consume a lot of
computing power (suppose the input string is 1 MByte or
even 1 GByte). In this case you don't have a problem
with padding but with leading zeroes.
But I still don't understand the advantage over base16.
If you only can use A-Z as transferable digits, you can
use an alternative to the standard hex encoding:
0 A or Q
1 B or R
2 C or S
3 D or T
4 E or U
5 F or V
6 G or W
7 H or X
8 I or Y
9 J or Z
10 K
11 L
12 M
13 N
14 O
15 P
Because there are two ways to encode 0-9, you
can use this to send a second data stream. If
A-J is used a 0 bit transferred and if Q-Z is used
a 1 bit is transferred on this second channel. You
can use this for example for a check sum or an
error correcting code.
If you only can use A-Z as transferable digits, you can
use an alternative to the standard hex encoding:
0 A or Q
1 B or R
2 C or S
3 D or T
4 E or U
5 F or V
6 G or W
7 H or X
8 I or Y
9 J or Z
10 K
11 L
12 M
13 N
14 O
15 P
Because there are two ways to encode 0-9, you
can use this to send a second data stream. If
A-J is used a 0 bit transferred and if Q-Z is used
a 1 bit is transferred on this second channel. You
can use this for example for a check sum or an
error correcting code.
Herbert Kleebauer wrote:
If you only can use A-Z as transferable digits, you can
use an alternative to the standard hex encoding:
0 A or Q
1 B or R
2 C or S
3 D or T
4 E or U
5 F or V
6 G or W
7 H or X
8 I or Y
9 J or Z
10 K
11 L
12 M
13 N
14 O
15 P
Because there are two ways to encode 0-9, you
can use this to send a second data stream. If
A-J is used a 0 bit transferred and if Q-Z is used
a 1 bit is transferred on this second channel. You
can use this for example for a check sum or an
error correcting code.
Would this be the correct output for A-Z encoding?
$ echo -n 'sci.crypt is cool! :-)' | ./az XDGTWJCOWDHSXJHQXECQWJHTSAGTWPGPWMCRSADKSNCZ
$ echo -n 'sci.crypt is cool! :-)' | base16 7363692e637279707420697320636f6f6c21203a2d29
Well, a new tool to play with, thanks to Herbert's
suggestion. :-)
Ok. I created 1000 random bytes with OpenSSL, converted
them with az, with a line length of 50 characters set.
Then the file was opened in LibreOffice, with the settings
of 16 pt, Liberation Mono font and saved as .pdf. With
these settings, 2000 characters fit exactly in an A4 page.
On 30.04.2024 16:43, Stefan Claas wrote:
Ok. I created 1000 random bytes with OpenSSL, converted
them with az, with a line length of 50 characters set.
Then the file was opened in LibreOffice, with the settings
of 16 pt, Liberation Mono font and saved as .pdf. With
these settings, 2000 characters fit exactly in an A4 page.
But QR code exists since a long time. This is also
a pdf with one A4 page, but if you decode it, you get
a 10 kByte jpg, which is 10x the amount of data of your
text page.
http://onlib.de/temp/demo.pdf
And if you have more data to transfer, use a QR code
video, for example:
http://onlib.de/temp/qr.mp4
You can upload your video to youtube, so anybody can
download and decode it.
If you decode the QR code video, you will get a zip file
with some pictures. The password for the pictures is:
"The quick brown fox jump"
On 01.05.2024 10:29, Stefan Claas wrote:
I decoded the image and had one error in the certutil file
(one byte missing in one line at the end). The video was
also a certutil file, but with to many errors, so it wrote
a bad .mp4, which I could not decode.
How did you manage to precisely insert 12 QR-Codes nicely on
an A4 page?
Some time ago I wrote a batch to make a paper backup
from a 13 kByte binary file (so it will make only two
pages with 12 QR codes each). The input file is hard
coded (t.jpg in this case). qrencode.exe I downloaded
somewhere from the internet and convert.exe is the
universal picture tool from https://imagemagick.org .
split.exe just splits the input file in small chunks
to be encoded in single QR code (source at the end of
this post). To get the binary back from the paper print,
you have just to start a text editor and scan all the
QR codes with a Bluetooth QR code scanner (which works
like an external Bluetooth keyboard). Then execute the
generated batch file to generate the binary.
[...]
I decoded the image and had one error in the certutil file
(one byte missing in one line at the end). The video was
also a certutil file, but with to many errors, so it wrote
a bad .mp4, which I could not decode.
How did you manage to precisely insert 12 QR-Codes nicely on
an A4 page?
tmp.txt echo @echo off
tmp.txt echo certutil -f -decode %%~f0 dmeo.jpg^>nul
tmp.txt echo goto :eof
Herbert Kleebauer wrote:
On 01.05.2024 10:29, Stefan Claas wrote:
I decoded the image and had one error in the certutil file
(one byte missing in one line at the end). The video was
also a certutil file, but with to many errors, so it wrote
a bad .mp4, which I could not decode.
How did you manage to precisely insert 12 QR-Codes nicely on
an A4 page?
Some time ago I wrote a batch to make a paper backup
from a 13 kByte binary file (so it will make only two
pages with 12 QR codes each). The input file is hard
coded (t.jpg in this case). qrencode.exe I downloaded
somewhere from the internet and convert.exe is the
universal picture tool from https://imagemagick.org .
split.exe just splits the input file in small chunks
to be encoded in single QR code (source at the end of
this post). To get the binary back from the paper print,
you have just to start a text editor and scan all the
QR codes with a Bluetooth QR code scanner (which works
like an external Bluetooth keyboard). Then execute the
generated batch file to generate the binary.
[...]
Thanks a lot or your help, much appreciated!
While I still cannot decode the video, I have now my own
solution.
Here is the Python3 code:
import qrcode
import os
import argparse
import shutil
from pyzbar.pyzbar import decode
from PIL import Image
import base64
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file', help='File to convert to/from QR codes') parser.add_argument('-e', '--encode', help='Directory to save QR codes', default=None)
parser.add_argument('-d', '--decode', help='Directory to load QR codes from', default=None)
args = parser.parse_args()
def file_to_qrcodes(file_path, directory):
with open(file_path, 'rb') as f:
counter = 0
ffmpeg -i "$FOLDERFILENAME" -start_number 0 "$DIRNAME/qr%d.png"
Stefan Claas wrote:
While I still cannot decode the video, I have now my own
solution.
Here is the Python3 code:
import qrcode
import os
import argparse
import shutil
from pyzbar.pyzbar import decode
from PIL import Image
import base64
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file', help='File to convert to/from QR codes')
parser.add_argument('-e', '--encode', help='Directory to save QR codes', default=None)
parser.add_argument('-d', '--decode', help='Directory to load QR codes from', default=None)
args = parser.parse_args()
def file_to_qrcodes(file_path, directory):
with open(file_path, 'rb') as f:
counter = 0
Set counter to 1 for my following bash script[1].
ffmpeg -i "$FOLDERFILENAME" -start_number 0 "$DIRNAME/qr%d.png"
and remove -start_number 0
[1] <https://github.com/stefanclaas/QR-Code-Helpers/blob/main/qr2page.sh>
which allows you to print QR-Codes, nicely formatted, on paper, like
Herbert has shown in his example.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 151:20:00 |
Calls: | 10,383 |
Files: | 14,054 |
Messages: | 6,417,800 |