#!/bin/sh

# Ahaha mais trop facile le CRC32 en shell (et sans tricher)

t00=00000000; h0=00; o0=000; x00=0
t01=77073096; h1=01; o1=001; x01=1
t02=ee0e612c; h2=02; o2=002; x02=2
t03=990951ba; h3=03; o3=003; x03=3
t04=076dc419; h4=04; o4=004; x04=4
t05=706af48f; h5=05; o5=005; x05=5
t06=e963a535; h6=06; o6=006; x06=6
t07=9e6495a3; h7=07; o7=007; x07=7
t08=0edb8832; h8=08; o8=010; x08=8
t09=79dcb8a4; h9=09; o9=011; x09=9
t0a=e0d5e91e; h10=0a; o10=012; x0a=a
t0b=97d2d988; h11=0b; o11=013; x0b=b
t0c=09b64c2b; h12=0c; o12=014; x0c=c
t0d=7eb17cbd; h13=0d; o13=015; x0d=d
t0e=e7b82d07; h14=0e; o14=016; x0e=e
t0f=90bf1d91; h15=0f; o15=017; x0f=f
t10=1db71064; h16=10; o16=020; x10=1
t11=6ab020f2; h17=11; o17=021; x11=0
t12=f3b97148; h18=12; o18=022; x12=3
t13=84be41de; h19=13; o19=023; x13=2
t14=1adad47d; h20=14; o20=024; x14=5
t15=6ddde4eb; h21=15; o21=025; x15=4
t16=f4d4b551; h22=16; o22=026; x16=7
t17=83d385c7; h23=17; o23=027; x17=6
t18=136c9856; h24=18; o24=030; x18=9
t19=646ba8c0; h25=19; o25=031; x19=8
t1a=fd62f97a; h26=1a; o26=032; x1a=b
t1b=8a65c9ec; h27=1b; o27=033; x1b=a
t1c=14015c4f; h28=1c; o28=034; x1c=d
t1d=63066cd9; h29=1d; o29=035; x1d=c
t1e=fa0f3d63; h30=1e; o30=036; x1e=f
t1f=8d080df5; h31=1f; o31=037; x1f=e
t20=3b6e20c8; h32=20; o32=040; x20=2
t21=4c69105e; h33=21; o33=041; x21=3
t22=d56041e4; h34=22; o34=042; x22=0
t23=a2677172; h35=23; o35=043; x23=1
t24=3c03e4d1; h36=24; o36=044; x24=6
t25=4b04d447; h37=25; o37=045; x25=7
t26=d20d85fd; h38=26; o38=046; x26=4
t27=a50ab56b; h39=27; o39=047; x27=5
t28=35b5a8fa; h40=28; o40=050; x28=a
t29=42b2986c; h41=29; o41=051; x29=b
t2a=dbbbc9d6; h42=2a; o42=052; x2a=8
t2b=acbcf940; h43=2b; o43=053; x2b=9
t2c=32d86ce3; h44=2c; o44=054; x2c=e
t2d=45df5c75; h45=2d; o45=055; x2d=f
t2e=dcd60dcf; h46=2e; o46=056; x2e=c
t2f=abd13d59; h47=2f; o47=057; x2f=d
t30=26d930ac; h48=30; o48=060; x30=3
t31=51de003a; h49=31; o49=061; x31=2
t32=c8d75180; h50=32; o50=062; x32=1
t33=bfd06116; h51=33; o51=063; x33=0
t34=21b4f4b5; h52=34; o52=064; x34=7
t35=56b3c423; h53=35; o53=065; x35=6
t36=cfba9599; h54=36; o54=066; x36=5
t37=b8bda50f; h55=37; o55=067; x37=4
t38=2802b89e; h56=38; o56=070; x38=b
t39=5f058808; h57=39; o57=071; x39=a
t3a=c60cd9b2; h58=3a; o58=072; x3a=9
t3b=b10be924; h59=3b; o59=073; x3b=8
t3c=2f6f7c87; h60=3c; o60=074; x3c=f
t3d=58684c11; h61=3d; o61=075; x3d=e
t3e=c1611dab; h62=3e; o62=076; x3e=d
t3f=b6662d3d; h63=3f; o63=077; x3f=c
t40=76dc4190; h64=40; o64=100; x40=4
t41=01db7106; h65=41; o65=101; x41=5
t42=98d220bc; h66=42; o66=102; x42=6
t43=efd5102a; h67=43; o67=103; x43=7
t44=71b18589; h68=44; o68=104; x44=0
t45=06b6b51f; h69=45; o69=105; x45=1
t46=9fbfe4a5; h70=46; o70=106; x46=2
t47=e8b8d433; h71=47; o71=107; x47=3
t48=7807c9a2; h72=48; o72=110; x48=c
t49=0f00f934; h73=49; o73=111; x49=d
t4a=9609a88e; h74=4a; o74=112; x4a=e
t4b=e10e9818; h75=4b; o75=113; x4b=f
t4c=7f6a0dbb; h76=4c; o76=114; x4c=8
t4d=086d3d2d; h77=4d; o77=115; x4d=9
t4e=91646c97; h78=4e; o78=116; x4e=a
t4f=e6635c01; h79=4f; o79=117; x4f=b
t50=6b6b51f4; h80=50; o80=120; x50=5
t51=1c6c6162; h81=51; o81=121; x51=4
t52=856530d8; h82=52; o82=122; x52=7
t53=f262004e; h83=53; o83=123; x53=6
t54=6c0695ed; h84=54; o84=124; x54=1
t55=1b01a57b; h85=55; o85=125; x55=0
t56=8208f4c1; h86=56; o86=126; x56=3
t57=f50fc457; h87=57; o87=127; x57=2
t58=65b0d9c6; h88=58; o88=130; x58=d
t59=12b7e950; h89=59; o89=131; x59=c
t5a=8bbeb8ea; h90=5a; o90=132; x5a=f
t5b=fcb9887c; h91=5b; o91=133; x5b=e
t5c=62dd1ddf; h92=5c; o92=134; x5c=9
t5d=15da2d49; h93=5d; o93=135; x5d=8
t5e=8cd37cf3; h94=5e; o94=136; x5e=b
t5f=fbd44c65; h95=5f; o95=137; x5f=a
t60=4db26158; h96=60; o96=140; x60=6
t61=3ab551ce; h97=61; o97=141; x61=7
t62=a3bc0074; h98=62; o98=142; x62=4
t63=d4bb30e2; h99=63; o99=143; x63=5
t64=4adfa541; h100=64; o100=144; x64=2
t65=3dd895d7; h101=65; o101=145; x65=3
t66=a4d1c46d; h102=66; o102=146; x66=0
t67=d3d6f4fb; h103=67; o103=147; x67=1
t68=4369e96a; h104=68; o104=150; x68=e
t69=346ed9fc; h105=69; o105=151; x69=f
t6a=ad678846; h106=6a; o106=152; x6a=c
t6b=da60b8d0; h107=6b; o107=153; x6b=d
t6c=44042d73; h108=6c; o108=154; x6c=a
t6d=33031de5; h109=6d; o109=155; x6d=b
t6e=aa0a4c5f; h110=6e; o110=156; x6e=8
t6f=dd0d7cc9; h111=6f; o111=157; x6f=9
t70=5005713c; h112=70; o112=160; x70=7
t71=270241aa; h113=71; o113=161; x71=6
t72=be0b1010; h114=72; o114=162; x72=5
t73=c90c2086; h115=73; o115=163; x73=4
t74=5768b525; h116=74; o116=164; x74=3
t75=206f85b3; h117=75; o117=165; x75=2
t76=b966d409; h118=76; o118=166; x76=1
t77=ce61e49f; h119=77; o119=167; x77=0
t78=5edef90e; h120=78; o120=170; x78=f
t79=29d9c998; h121=79; o121=171; x79=e
t7a=b0d09822; h122=7a; o122=172; x7a=d
t7b=c7d7a8b4; h123=7b; o123=173; x7b=c
t7c=59b33d17; h124=7c; o124=174; x7c=b
t7d=2eb40d81; h125=7d; o125=175; x7d=a
t7e=b7bd5c3b; h126=7e; o126=176; x7e=9
t7f=c0ba6cad; h127=7f; o127=177; x7f=8
t80=edb88320; h128=80; o128=200; x80=8
t81=9abfb3b6; h129=81; o129=201; x81=9
t82=03b6e20c; h130=82; o130=202; x82=a
t83=74b1d29a; h131=83; o131=203; x83=b
t84=ead54739; h132=84; o132=204; x84=c
t85=9dd277af; h133=85; o133=205; x85=d
t86=04db2615; h134=86; o134=206; x86=e
t87=73dc1683; h135=87; o135=207; x87=f
t88=e3630b12; h136=88; o136=210; x88=0
t89=94643b84; h137=89; o137=211; x89=1
t8a=0d6d6a3e; h138=8a; o138=212; x8a=2
t8b=7a6a5aa8; h139=8b; o139=213; x8b=3
t8c=e40ecf0b; h140=8c; o140=214; x8c=4
t8d=9309ff9d; h141=8d; o141=215; x8d=5
t8e=0a00ae27; h142=8e; o142=216; x8e=6
t8f=7d079eb1; h143=8f; o143=217; x8f=7
t90=f00f9344; h144=90; o144=220; x90=9
t91=8708a3d2; h145=91; o145=221; x91=8
t92=1e01f268; h146=92; o146=222; x92=b
t93=6906c2fe; h147=93; o147=223; x93=a
t94=f762575d; h148=94; o148=224; x94=d
t95=806567cb; h149=95; o149=225; x95=c
t96=196c3671; h150=96; o150=226; x96=f
t97=6e6b06e7; h151=97; o151=227; x97=e
t98=fed41b76; h152=98; o152=230; x98=1
t99=89d32be0; h153=99; o153=231; x99=0
t9a=10da7a5a; h154=9a; o154=232; x9a=3
t9b=67dd4acc; h155=9b; o155=233; x9b=2
t9c=f9b9df6f; h156=9c; o156=234; x9c=5
t9d=8ebeeff9; h157=9d; o157=235; x9d=4
t9e=17b7be43; h158=9e; o158=236; x9e=7
t9f=60b08ed5; h159=9f; o159=237; x9f=6
ta0=d6d6a3e8; h160=a0; o160=240; xa0=a
ta1=a1d1937e; h161=a1; o161=241; xa1=b
ta2=38d8c2c4; h162=a2; o162=242; xa2=8
ta3=4fdff252; h163=a3; o163=243; xa3=9
ta4=d1bb67f1; h164=a4; o164=244; xa4=e
ta5=a6bc5767; h165=a5; o165=245; xa5=f
ta6=3fb506dd; h166=a6; o166=246; xa6=c
ta7=48b2364b; h167=a7; o167=247; xa7=d
ta8=d80d2bda; h168=a8; o168=250; xa8=2
ta9=af0a1b4c; h169=a9; o169=251; xa9=3
taa=36034af6; h170=aa; o170=252; xaa=0
tab=41047a60; h171=ab; o171=253; xab=1
tac=df60efc3; h172=ac; o172=254; xac=6
tad=a867df55; h173=ad; o173=255; xad=7
tae=316e8eef; h174=ae; o174=256; xae=4
taf=4669be79; h175=af; o175=257; xaf=5
tb0=cb61b38c; h176=b0; o176=260; xb0=b
tb1=bc66831a; h177=b1; o177=261; xb1=a
tb2=256fd2a0; h178=b2; o178=262; xb2=9
tb3=5268e236; h179=b3; o179=263; xb3=8
tb4=cc0c7795; h180=b4; o180=264; xb4=f
tb5=bb0b4703; h181=b5; o181=265; xb5=e
tb6=220216b9; h182=b6; o182=266; xb6=d
tb7=5505262f; h183=b7; o183=267; xb7=c
tb8=c5ba3bbe; h184=b8; o184=270; xb8=3
tb9=b2bd0b28; h185=b9; o185=271; xb9=2
tba=2bb45a92; h186=ba; o186=272; xba=1
tbb=5cb36a04; h187=bb; o187=273; xbb=0
tbc=c2d7ffa7; h188=bc; o188=274; xbc=7
tbd=b5d0cf31; h189=bd; o189=275; xbd=6
tbe=2cd99e8b; h190=be; o190=276; xbe=5
tbf=5bdeae1d; h191=bf; o191=277; xbf=4
tc0=9b64c2b0; h192=c0; o192=300; xc0=c
tc1=ec63f226; h193=c1; o193=301; xc1=d
tc2=756aa39c; h194=c2; o194=302; xc2=e
tc3=026d930a; h195=c3; o195=303; xc3=f
tc4=9c0906a9; h196=c4; o196=304; xc4=8
tc5=eb0e363f; h197=c5; o197=305; xc5=9
tc6=72076785; h198=c6; o198=306; xc6=a
tc7=05005713; h199=c7; o199=307; xc7=b
tc8=95bf4a82; h200=c8; o200=310; xc8=4
tc9=e2b87a14; h201=c9; o201=311; xc9=5
tca=7bb12bae; h202=ca; o202=312; xca=6
tcb=0cb61b38; h203=cb; o203=313; xcb=7
tcc=92d28e9b; h204=cc; o204=314; xcc=0
tcd=e5d5be0d; h205=cd; o205=315; xcd=1
tce=7cdcefb7; h206=ce; o206=316; xce=2
tcf=0bdbdf21; h207=cf; o207=317; xcf=3
td0=86d3d2d4; h208=d0; o208=320; xd0=d
td1=f1d4e242; h209=d1; o209=321; xd1=c
td2=68ddb3f8; h210=d2; o210=322; xd2=f
td3=1fda836e; h211=d3; o211=323; xd3=e
td4=81be16cd; h212=d4; o212=324; xd4=9
td5=f6b9265b; h213=d5; o213=325; xd5=8
td6=6fb077e1; h214=d6; o214=326; xd6=b
td7=18b74777; h215=d7; o215=327; xd7=a
td8=88085ae6; h216=d8; o216=330; xd8=5
td9=ff0f6a70; h217=d9; o217=331; xd9=4
tda=66063bca; h218=da; o218=332; xda=7
tdb=11010b5c; h219=db; o219=333; xdb=6
tdc=8f659eff; h220=dc; o220=334; xdc=1
tdd=f862ae69; h221=dd; o221=335; xdd=0
tde=616bffd3; h222=de; o222=336; xde=3
tdf=166ccf45; h223=df; o223=337; xdf=2
te0=a00ae278; h224=e0; o224=340; xe0=e
te1=d70dd2ee; h225=e1; o225=341; xe1=f
te2=4e048354; h226=e2; o226=342; xe2=c
te3=3903b3c2; h227=e3; o227=343; xe3=d
te4=a7672661; h228=e4; o228=344; xe4=a
te5=d06016f7; h229=e5; o229=345; xe5=b
te6=4969474d; h230=e6; o230=346; xe6=8
te7=3e6e77db; h231=e7; o231=347; xe7=9
te8=aed16a4a; h232=e8; o232=350; xe8=6
te9=d9d65adc; h233=e9; o233=351; xe9=7
tea=40df0b66; h234=ea; o234=352; xea=4
teb=37d83bf0; h235=eb; o235=353; xeb=5
tec=a9bcae53; h236=ec; o236=354; xec=2
ted=debb9ec5; h237=ed; o237=355; xed=3
tee=47b2cf7f; h238=ee; o238=356; xee=0
tef=30b5ffe9; h239=ef; o239=357; xef=1
tf0=bdbdf21c; h240=f0; o240=360; xf0=f
tf1=cabac28a; h241=f1; o241=361; xf1=e
tf2=53b39330; h242=f2; o242=362; xf2=d
tf3=24b4a3a6; h243=f3; o243=363; xf3=c
tf4=bad03605; h244=f4; o244=364; xf4=b
tf5=cdd70693; h245=f5; o245=365; xf5=a
tf6=54de5729; h246=f6; o246=366; xf6=9
tf7=23d967bf; h247=f7; o247=367; xf7=8
tf8=b3667a2e; h248=f8; o248=370; xf8=7
tf9=c4614ab8; h249=f9; o249=371; xf9=6
tfa=5d681b02; h250=fa; o250=372; xfa=5
tfb=2a6f2b94; h251=fb; o251=373; xfb=4
tfc=b40bbe37; h252=fc; o252=374; xfc=3
tfd=c30c8ea1; h253=fd; o253=375; xfd=2
tfe=5a05df1b; h254=fe; o254=376; xfe=1
tff=2d02ef8d; h255=ff; o255=377; xff=0

xor() {
  a="$1"
  b="$2"
  result=""
  while test "$a" != ""; do
    result="$result$(eval 'echo $x'${a%${a#?}}${b%${b#?}})"
    a=${a#?}
    b=${b#?}
  done
  echo $result
}

char2hex() {
  i=0
  while test "$i" != 256; do
    oct=$(eval 'echo $o'$i)
    if test "x$(printf '\'$oct)" = "x$1"; then eval 'echo $h'$i; return; fi
    i=$(($i + 1))
  done
  echo 00
}

string="$1"
crc=ffffffff

while test "$string" != ""; do
   crc=$(xor `eval 'echo $t'$(xor $(char2hex "${string%${string#?}}") ${crc#??????})` 00${crc%??})
   string="${string#?}"
done

xor $crc ffffffff

