update test/md5compare.nas
and CAUTION: now the cpp&nas md5 program may not calculate strings including unicode
This commit is contained in:
parent
c5a12ade5c
commit
41b5304712
11
test/md5.nas
11
test/md5.nas
|
@ -55,12 +55,12 @@ var u32_bits_not=func(x){
|
|||
}
|
||||
|
||||
var hex32str=func(num){
|
||||
var ch="0123456789abcdef";
|
||||
var ch=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
|
||||
var res="";
|
||||
for(var i=0;i<4;i+=1){
|
||||
var tmp="";
|
||||
for(var j=0;j<2;j+=1){
|
||||
tmp=chr(ch[u32_bits_and(num,0x0f)])~tmp;
|
||||
tmp=ch[u32_bits_and(num,0x0f)]~tmp;
|
||||
num=int(num/16);
|
||||
}
|
||||
res~=tmp;
|
||||
|
@ -138,11 +138,12 @@ var _md5=func(s){
|
|||
|
||||
var len=size(s)*8;
|
||||
var res=[];
|
||||
setsize(res,len);
|
||||
var v=[128,64,32,16,8,4,2,1];
|
||||
for(var i=0;i<size(s);i+=1){
|
||||
var c=s[i];
|
||||
foreach(var j;v){
|
||||
append(res,bits.bitand(c,j)?1:0);
|
||||
for(var j=0;j<8;j+=1){
|
||||
res[i*8+j]=(bits.bitand(c,v[j])?1:0);
|
||||
}
|
||||
}
|
||||
# +------len------+--1~512--+--64--+
|
||||
|
@ -190,6 +191,8 @@ var _md5=func(s){
|
|||
res=tmp;
|
||||
|
||||
# 1 block=>16 uint32=>64 byte=>512 bit
|
||||
# because using double to discribe number
|
||||
# this may only work when string's length is under 1<<51
|
||||
tmp=[];
|
||||
for(var i=0;i<size(res);i+=4){
|
||||
append(tmp,
|
||||
|
|
|
@ -5,12 +5,16 @@ import("test/md5.nas");
|
|||
rand(time(0));
|
||||
|
||||
var compare=func(total){
|
||||
var ch="0123456789abcdef+_*/\'\".,;:<>!@#$%^&*()-=\\|[]{}";
|
||||
var ch=[
|
||||
"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","+",
|
||||
"_","*","/","\'","\"",".",",",";",":","<",">","!","@","#","$","%",
|
||||
"^","&","*","(",")","-","=","\\","|","[","]","{","}","`"," ","\t","?"
|
||||
];
|
||||
var (prt,lastpercent,percent)=("",0,0);
|
||||
for(var i=1;i<=total;i+=1){
|
||||
var s="";
|
||||
for(var j=0;j<i;j+=1){
|
||||
s~=chr(ch[int(rand()*size(ch))]);
|
||||
s~=ch[int(rand()*size(ch))];
|
||||
}
|
||||
if(cmp(md5(s),_md5(s))){
|
||||
die("error: "~str(i));
|
||||
|
@ -28,6 +32,64 @@ var compare=func(total){
|
|||
print('\n');
|
||||
}
|
||||
|
||||
compare(512);
|
||||
compare(1024);
|
||||
compare(2048);
|
||||
var filechecksum=func(){
|
||||
var getname=func(s){
|
||||
var (len,ch)=(size(s),' '[0]);
|
||||
for(var i=0;i<len and s[i]!=ch;i+=1);
|
||||
return substr(s,0,i);
|
||||
}
|
||||
var filewithoututf8=[
|
||||
"./test/auto_crash.nas ",
|
||||
"./test/bf.nas ",
|
||||
"./test/bfcolored.nas ",
|
||||
"./test/bfconvertor.nas ",
|
||||
"./test/bfs.nas ",
|
||||
"./test/bigloop.nas ",
|
||||
"./test/bp.nas ",
|
||||
"./test/calc.nas ",
|
||||
"./test/choice.nas ",
|
||||
"./test/class.nas ",
|
||||
"./test/exception.nas ",
|
||||
"./test/fib.nas ",
|
||||
"./test/filesystem.nas ",
|
||||
"./test/hexdump.nas ",
|
||||
"./test/json.nas ",
|
||||
"./test/leetcode1319.nas ",
|
||||
"./test/lexer.nas ",
|
||||
"./test/life.nas ",
|
||||
"./test/loop.nas ",
|
||||
"./test/mandel.nas ",
|
||||
"./test/mandelbrot.nas ",
|
||||
"./test/md5.nas ",
|
||||
"./test/md5compare.nas ",
|
||||
"./test/module_test.nas ",
|
||||
"./test/nasal_test.nas ",
|
||||
"./test/pi.nas ",
|
||||
"./test/prime.nas ",
|
||||
"./test/props_sim.nas ",
|
||||
"./test/props.nas ",
|
||||
"./test/quick_sort.nas ",
|
||||
"./test/scalar.nas ",
|
||||
"./test/trait.nas ",
|
||||
"./test/turingmachine.nas",
|
||||
"./test/ycombinator.nas "
|
||||
];
|
||||
foreach(var i;filewithoututf8){
|
||||
var f=io.fin(getname(i));
|
||||
var (res0,res1)=(md5(f),_md5(f));
|
||||
println(i,' ',res0,' ',!cmp(res0,res1),' ',size(f),' byte');
|
||||
}
|
||||
}
|
||||
|
||||
var randomchecksum=func(){
|
||||
for(var i=0;i<8;i+=1)
|
||||
compare(512);
|
||||
for(var i=0;i<4;i+=1)
|
||||
compare(1024);
|
||||
for(var i=0;i<2;i+=1)
|
||||
compare(2048);
|
||||
compare(4096);
|
||||
}
|
||||
|
||||
filechecksum();
|
||||
randomchecksum();
|
Loading…
Reference in New Issue