Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Phil Carmody <pc+usenet@asdf.org> |
|---|---|
| Newsgroups | sci.crypt |
| Subject | Re: CHATX - a thread starter that's not as easy as it looks. |
| Date | 2021-09-26 14:39 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <87zgrzd0rj.fsf@zotaspaz.fatphil.org> (permalink) |
| References | <si9jk4$188$1@dont-email.me> <siakbv$j80$1@gioia.aioe.org> <siakmd$ilv$1@dont-email.me> <87czp2do4k.fsf@zotaspaz.fatphil.org> <sin17b$n7$1@dont-email.me> |
wizzofozz <oxxxxxxxxxxxs@gmail.com> writes:
> When I finally came to implementing the encryption I figured I needed
> to make every line length a multiple of 4. This is probably related.
> I like the perl onelines, but I always find perl a bit hard to read.
> My solutions also have the mod 2 = 1/0 , but that's probably logical.
>
> In my other post I encrypted base64 encodings of my python solutions.
> Here are my versions (finalized late at night so a bit messy as usual):
>
> decrypt:
> #!/usr/bin/python
>
> import sys
>
> x=open(sys.argv[1]).readlines()
>
> def m(a,b):
> if len(a) != len(b):
> print "bad"
> la = len(a)
> if la%2==0:
> a+=" "
> b+=" "
> la += 1
> i=1
> pt=""
> while i < la*2:
> pt += (a[i%la] + b[i%la])
> i += 2
> return pt
>
> for l in range(len(x)/2):
> print m(x[l*2].rstrip('\n'),x[2*l+1].rstrip('\n'))
>
>
>
> encrypt:
> #!/usr/bin/python
> import sys
>
> x=open(sys.argv[1]).readlines()
>
> for l in x:
> pt = l.rstrip('\n')
> lpt = len(pt)
> if lpt % 4 != 0:
> pt += "x"*(4-lpt%4)
> lpt = len(pt)
> b=[pt[lpt/2+j]+pt[j] for j in range(lpt/2)]
> print "".join([b[i] for i in range(len(b)) if i % 2 == 0])
> print "".join([b[i] for i in range(len(b)) if i % 2 == 1])
Assuming I've got the line ending/length protocols correct:
--- 8< ---- encoder -----
#!/usr/bin/perl -w
use strict;
use warnings;
my ($it,$ib);
while(defined($it=<>) and defined($ib=<>)) {
chomp($it); chomp($ib);
my ($lt,$lb)=(length($it),length($ib));
if($lt&1) { $it.=' '; $lt++; }
if($lb&1) { $ib.=' '; $lb++; }
if($lt<$lb) { $it.='x'x($lb-$lt); $lt=$lb; }
if($lt>$lb) { $ib.='x'x($lt-$lb); $lb=$lt; }
for my $o (0..1) {
for(my $i=0; $i<$lt; $i+=2) {
print(substr($ib,$i+$o,1),substr($it,$i+$o,1));
}
print("\n");
}
}
--- 8< ---- encoder test -----
echo "For those of you still on
lockdown, can you identify
the algorithm used to encrypt
this text?
For extra credit, cut some code
that can approximate a decryption
-- harder than it looks, as I can
attest.
And don't say nothing
ever happens here." | perl r4.pl
lFcrdtwo,econ you itelt fn
ook ohns af you sdinlioy
ttie aegtrxtxmxuxex xoxexcxyxt
hhs tlxo?ixhx xsxdxtx xnxrxpx
tFar eat apcrexim,tc t semr poienx
hot cxnra prodita eua doceyctdo x
a-t sa.dxrxtxax xtxlxoxsx xsxIxcxn
t-ehtr ex xhxnxix xoxkx,xax x xax
eAed danptns yenetxixg
vnr hop'e sah ro.hxnx
--- 8< ---- encoder test end -----
--- 8< ---- decoder -----
#!/usr/bin/perl -w
use strict;
use warnings;
my ($it,$ib);
while(defined($it=<>) and defined($ib=<>)) {
chomp($it); chomp($ib);
my ($lt,$lb)=(length($it),length($ib));
die("lengths not equal: '$it'=$lt '$ib'=$lb")if($lt!=$lb);
die("lengths not even: '$it'=$lt '$ib'=$lb")if($lt&1);
my @o=('','');
for my $o (0..1) {
for(my $i=0; $i<$lt; $i+=2) {
$o[$o^1].=substr($it,$i+$o,1).substr($ib,$i+$o,1);
}
$o[0]=~s/ ?x+$//; $o[1]=~s/ ?x+$//;
}
print("$o[0]\n$o[1]\n");
}
--- 8< ---- decoder test -----
echo "lFcrdtwo,econ you itelt fn
ook ohns af you sdinlioy
ttie aegtrxtxmxuxex xoxexcxyxt
hhs tlxo?ixhx xsxdxtx xnxrxpx
tFar eat apcrexim,tc t semr poienx
hot cxnra prodita eua doceyctdo x
a-t sa.dxrxtxax xtxlxoxsx xsxIxcxn
t-ehtr ex xhxnxix xoxkx,xax x xax
eAed danptns yenetxixg
vnr hop'e sah ro.hxnx " | perl r4d.pl
For those of you still on
lockdown, can you identify
the algorithm used to encrypt
this text?
For extra credit, cut some code
that can approximate a decryption
-- harder than it looks, as I can
attest.
And don't say nothing
ever happens here.
--- 8< ---- decoder test end -----
Note, the decoder uses my encoder output as its input, not Richard's
original.
Phil
--
We are no longer hunters and nomads. No longer awed and frightened, as we have
gained some understanding of the world in which we live. As such, we can cast
aside childish remnants from the dawn of our civilization.
-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/
Back to sci.crypt | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-20 10:17 +0100
Re: CHATX - a thread starter that's not as easy as it looks. MM <mrvmurray@gmail.com> - 2021-09-20 07:00 -0700
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-20 15:17 +0100
Re: CHATX - a thread starter that's not as easy as it looks. MM <mrvmurray@gmail.com> - 2021-09-20 10:52 -0700
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-20 19:10 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Max <maxturv26@gmx.net> - 2021-09-20 20:36 +0200
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-20 19:42 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Max <maxturv26@gmx.net> - 2021-09-20 20:50 +0200
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-20 21:02 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Max <maxturv26@gmx.net> - 2021-09-20 22:24 +0200
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-20 22:08 +0100
Re: CHATX - a thread starter that's not as easy as it looks. wizzofozz <oxxxxxxxxxxxs@gmail.com> - 2021-09-20 21:43 +0200
Re: CHATX - a thread starter that's not as easy as it looks. Max <maxturv26@gmx.net> - 2021-09-20 21:50 +0200
Re: CHATX - a thread starter that's not as easy as it looks. Phil Carmody <pc+usenet@asdf.org> - 2021-09-21 17:00 +0300
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-21 15:22 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Max <maxturv26@gmx.net> - 2021-09-21 23:31 +0200
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-21 23:03 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Max <maxturv26@gmx.net> - 2021-09-22 00:22 +0200
Re: CHATX - a thread starter that's not as easy as it looks. wizzofozz <oxxxxxxxxxxxs@gmail.com> - 2021-09-25 13:29 +0200
Re: CHATX - a thread starter that's not as easy as it looks. Phil Carmody <pc+usenet@asdf.org> - 2021-09-26 14:39 +0300
Re: CHATX - a thread starter that's not as easy as it looks. Richard Harnden <richard.nospam@gmail.com> - 2021-09-21 15:07 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-21 15:18 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Phil Carmody <pc+usenet@asdf.org> - 2021-09-21 21:43 +0300
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-21 20:41 +0100
Re: CHATX - a thread starter that's not as easy as it looks. wizzofozz <oxxxxxxxxxxxs@gmail.com> - 2021-09-25 02:24 +0200
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-25 05:24 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Richard Harnden <richard.nospam@gmail.com> - 2021-09-25 13:56 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-25 14:21 +0100
Re: CHATX - a thread starter that's not as easy as it looks. Richard Heathfield <rjh@cpax.org.uk> - 2021-09-25 14:28 +0100
Re: CHATX - a thread starter that's not as easy as it looks. wizzofozz <oxxxxxxxxxxxs@gmail.com> - 2021-09-25 16:11 +0200
csiph-web