Skip to content

Instantly share code, notes, and snippets.

@ohac
Created November 6, 2008 03:48
Show Gist options
  • Save ohac/22515 to your computer and use it in GitHub Desktop.
Save ohac/22515 to your computer and use it in GitHub Desktop.
encode.sh
#!/usr/bin/ruby
require 'base64'
require 'digest/md5'
b1 = ''
b2 = ''
s1 = ''
s2 = ''
open('b.txt') do |fd|
loop do
x = fd.readline
break if x.size == 1
b1 <<= x
end
loop do
x = fd.readline
break if x.size == 1
b2 <<= x.tr('B-Za-z0-9A', 'A-Za-z0-9')
end
s1 = fd.readline.chop
s2 = fd.readline.chop.tr('B-Za-z0-9A', 'A-Za-z0-9')
end
table = []
out = ''
b1.size.times do |i|
c = b1[i]
c2 = b2[i]
out << if c == c2
c
elsif (c >= ?0 && c <= ?9) || (c >= ?A && c <= ?Z) || (c >= ?a && c <= ?z)
if (c2 >= ?0 && c2 <= ?9) || (c2 >= ?A && c2 <= ?Z) || (c2 >= ?a && c2 <= ?z)
table << [ i, c, c2 ]
c
else
c
end
else
c2
end
end
table2 = []
sum = ''
s1.size.times do |i|
c = s1[i]
c2 = s2[i]
sum << if c == c2
c
elsif (c >= ?0 && c <= ?9) || (c >= ?a && c <= ?f)
if (c2 >= ?0 && c2 <= ?9) || (c2 >= ?a && c2 <= ?f)
table2 << [ i, c, c2 ]
c
else
c
end
c
else
c2
end
end
#p sum
#p table
#p table2
(2 ** table.size).times do |b|
table.size.times do |i|
t = table[i]
out[t[0]] = t[(b & (1 << i)) == 0 ? 1 : 2]
end
raw = Base64.decode64(out)
asum = Digest::MD5.hexdigest(raw)
t2 = 0
sum.size.times {|i| t2 += sum[i] == asum[i] ? 1 : 0 }
if t2 > 16
print raw
break
end
#puts [ sum, asum ]
end
#!/bin/bash
BASE64TEXT=`base64 -w0`
OCRFROM='uoYVNW6G0O2Z9g1'
OCRTO='$!?%#()<>[]{}_-'
echo $BASE64TEXT | tr $OCRFROM $OCRTO
echo
# Caesar cipher
echo $BASE64TEXT | tr A-Za-z0-9 B-Za-z0-9A | tr $OCRFROM $OCRTO
echo
SUM=`echo $BASE64TEXT | base64 -d | md5sum -b | cut -d' ' -f1`
echo $SUM | tr $OCRFROM $OCRTO
echo $SUM | tr A-Za-z0-9 B-Za-z0-9A | tr $OCRFROM $OCRTO
#!/bin/bash
OCRFROM='uoYVNW6G0O2Z9g1'
OCRTO='$!?%#()<>[]{}_-'
TMPDIR=`mktemp -d`
pushd $TMPDIR
convert $OLDPWD/$1 a.bmp
tesseract a.bmp a
cp a.txt $OLDPWD/a.txt
tr $OCRTO $OCRFROM <a.txt | lv -Iu8 -Ol0 >$OLDPWD/b.txt
popd
rm -fr $TMPDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment