Unnamed Fossil Project

Check-in [89d84d5d86]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:e64 and d64 for encoding and decoding base64
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:89d84d5d86d426d1a0279a2ed83571f64ef30fe8
User & Date: Derek 2013-02-27 17:51:01
Context
2013-02-27
17:53
an additional test of b64 and e64 check-in: aa02d9cc8b user: Derek tags: trunk
17:51
e64 and d64 for encoding and decoding base64 check-in: 89d84d5d86 user: Derek tags: trunk
16:46
decode written and tested. check-in: bd7e1086e7 user: Derek tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to maze.html.

54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83


84









85
86
87
88





89
90
91
92
93
94
95
lastk=lastk-l;k=0;
for(j=0;j<b.length;++j){
k=b[j][0];r[i++]=k-lastk;r[i++]=b[j][1];lastk=k;}
return r;}

//alert()
setTimeout(function(){

var q=encodelines({w:width,h:height,start:[startx,starty],end:[goalx,goaly],arr:arr});
alert(q.join(','));
alert(JSON.stringify(decodelines(q)));
}, 1000);

function decodelines(r){
var w,h,s=[],e=[],arr=[],i=0,j,c,lines=[];
w=r[i++];h=r[i++];l=w*h;for(j=0;j<l;++j)arr[j]=0;
c=r[i++];for(j=0;j<c;++j)s.push(r[i++]);//start
c=r[i++];for(j=0;j<c;++j)e.push(r[i++]);//end
c=r[i++];i+=c;//ignore destinations
alert(r.slice(i).join(','));
while(i<r.length)lines.push(r[i++]);
var d=1,a=0,b;
for(i=0;i<lines.length;i+=2){
a+=lines[i];b=lines[i+1];
if(a>l)if(d==1)a-=l,d=w;else break;
for(j=0;j<b;++j)arr[a+d*j]=1;}
if(arr[s[0]+s[1]*w])for(j=0;j<l;++j)arr[j]=arr[j]?0:1;//negate, start must be empty
return{w:w,h:h,start:s,end:e,arr:arr};}


function e64(arr){


}










function d64(str){
}







function save(){
localStorage.saved=false;
localStorage.mazestate=JSON.stringify(
{x:x,y:y,w:width,h:height,startx:startx,starty:starty,goalx:goalx,goaly:goaly,arr:arr});
localStorage.saved=true;}








>
|
|
|








<










|
>
>
|
>
>
>
>
>
>
>
>
>


<
<
>
>
>
>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97


98
99
100
101
102
103
104
105
106
107
108
109
lastk=lastk-l;k=0;
for(j=0;j<b.length;++j){
k=b[j][0];r[i++]=k-lastk;r[i++]=b[j][1];lastk=k;}
return r;}

//alert()
setTimeout(function(){
alert(e64([1,2,3,4,5,992]));
//var q=encodelines({w:width,h:height,start:[startx,starty],end:[goalx,goaly],arr:arr});
//alert(q.join(','));
//alert(JSON.stringify(decodelines(q)));
}, 1000);

function decodelines(r){
var w,h,s=[],e=[],arr=[],i=0,j,c,lines=[];
w=r[i++];h=r[i++];l=w*h;for(j=0;j<l;++j)arr[j]=0;
c=r[i++];for(j=0;j<c;++j)s.push(r[i++]);//start
c=r[i++];for(j=0;j<c;++j)e.push(r[i++]);//end
c=r[i++];i+=c;//ignore destinations

while(i<r.length)lines.push(r[i++]);
var d=1,a=0,b;
for(i=0;i<lines.length;i+=2){
a+=lines[i];b=lines[i+1];
if(a>l)if(d==1)a-=l,d=w;else break;
for(j=0;j<b;++j)arr[a+d*j]=1;}
if(arr[s[0]+s[1]*w])for(j=0;j<l;++j)arr[j]=arr[j]?0:1;//negate, start must be empty
return{w:w,h:h,start:s,end:e,arr:arr};}


var ch64="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_",ch64rev={};
(function(){for(var i=0;i<ch64.length;++i){ch64rev[ch64[i]]=i;}})();
alert(ch64[62]);

//lower half of charset has built in delimiter
function e64(arr){
var i,j,s="",x,a=[];
for(i=0;i<arr.length;++i){
x=arr[i];a.length=0;while(x>0){a.push(x%32);x=Math.floor(x/32);}
alert(a.join(','));
for(j=a.length-1;j>0;--j)s+=ch64[a[j]+32];
s+=ch64[a[0]];}
return s;}

function d64(str){


var i,x,y=0,a=[],arr=[];
for(i=0;i<str.length;++i){
x=ch64rev[str[i]];y=32*y+x-32;
if(x<32){y+=32;arr.push(y);y=0;}}
return arr;}

function save(){
localStorage.saved=false;
localStorage.mazestate=JSON.stringify(
{x:x,y:y,w:width,h:height,startx:startx,starty:starty,goalx:goalx,goaly:goaly,arr:arr});
localStorage.saved=true;}