]> gitweb.factorcode.org Git - factor.git/commitdiff
move base64 to contrib/base64
authorerg <erg@trifocus.net>
Sun, 12 Nov 2006 19:35:24 +0000 (19:35 +0000)
committererg <erg@trifocus.net>
Sun, 12 Nov 2006 19:35:24 +0000 (19:35 +0000)
contrib/README.txt
contrib/base64/base64.factor [new file with mode: 0644]
contrib/base64/load.factor [new file with mode: 0644]
contrib/base64/test.factor [new file with mode: 0644]
contrib/crypto/base64.factor [deleted file]
contrib/crypto/load.factor
contrib/crypto/test/base64.factor [deleted file]

index d0a0aebef7e186231835dc15dd53c3ca1db6e875..c6a4c762c8aded52339281fddc227c4c9dc8200b 100644 (file)
@@ -9,6 +9,7 @@ Available libraries:
 
 - alien -- Alien utility words (Eduardo Cavazos)
 - automata -- Graphics demo for the UI (Eduardo Cavazos)
+- base64 -- base64 encoding/decoding (Doug Coleman)
 - benchmarks -- Various performance benchmarks (Slava Pestov)
 - boids -- Graphics demo for the UI (Eduardo Cavazos)
 - cairo -- cairo bindings (Sampo Vuori)
diff --git a/contrib/base64/base64.factor b/contrib/base64/base64.factor
new file mode 100644 (file)
index 0000000..a4d4f09
--- /dev/null
@@ -0,0 +1,43 @@
+USING: kernel math sequences namespaces io strings hashtables ;
+IN: base64-internals
+
+: count-end ( seq quot -- count )
+    >r [ length ] keep r> find-last drop dup -1 = [ 2drop 0 ] [ - 1- ] if ;
+
+: ch>base64 ( ch -- ch )
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" nth ;
+
+: base64>ch ( ch -- ch )
+    {
+        f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f
+        f f f f f f f f f f 62 f f f 63 52 53 54 55 56 57 58 59 60 61 f f
+        f 0 f f f 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
+        22 23 24 25 f f f f f f 26 27 28 29 30 31 32 33 34 35 36 37 38 39
+        40 41 42 43 44 45 46 47 48 49 50 51
+    } nth ;
+
+: encode3 ( seq -- seq )
+    be> 4 [ 3 swap - -6 * shift HEX: 3f bitand ch>base64 ] map-with ;
+
+: decode4 ( str -- str )
+    [ base64>ch ] map 0 [ swap 6 shift bitor ] reduce 3 >be ;
+
+: >base64-rem ( str -- str )
+    [ 3 0 pad-right encode3 ] keep length 1+ head 4 CHAR: = pad-right ;
+
+IN: base64
+: >base64 ( str -- str )
+    #! cut string into two pieces, convert 3 bytes at a time
+    #! pad string with = when not enough bits
+    [ length dup 3 mod - ] keep cut swap
+    [
+        3 group [ encode3 % ] each
+        dup empty? [ drop ] [ >base64-rem % ] if
+    ] "" make ;
+
+: base64> ( str -- str )
+    #! input length must be a mulitple of 4
+    [
+        [ 4 group [ decode4 % ] each ] keep [ CHAR: = = not ] count-end 
+    ] SBUF" " make swap [ dup pop* ] times >string ;
+
diff --git a/contrib/base64/load.factor b/contrib/base64/load.factor
new file mode 100644 (file)
index 0000000..70de2d8
--- /dev/null
@@ -0,0 +1,7 @@
+PROVIDE: contrib/base64
+{ +files+ {
+    "base64.factor"
+} }
+{  +tests+ {
+    "test.factor"
+} } ;
diff --git a/contrib/base64/test.factor b/contrib/base64/test.factor
new file mode 100644 (file)
index 0000000..9bb1780
--- /dev/null
@@ -0,0 +1,8 @@
+USING: test base64 ;
+
+[ "abcdefghijklmnopqrstuvwxyz" ] [ "abcdefghijklmnopqrstuvwxyz" >base64 base64>
+] unit-test
+[ "" ] [ "" >base64 base64> ] unit-test
+[ "a" ] [ "a" >base64 base64> ] unit-test
+[ "ab" ] [ "ab" >base64 base64> ] unit-test
+[ "abc" ] [ "abc" >base64 base64> ] unit-test
diff --git a/contrib/crypto/base64.factor b/contrib/crypto/base64.factor
deleted file mode 100644 (file)
index ad6700c..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-USING: kernel math math-contrib sequences namespaces io strings hashtables ;
-IN: crypto-internals
-
-: ch>base64 ( ch -- ch )
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" nth ;
-
-: base64>ch ( ch -- ch )
-    {
-        f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f
-        f f f f f f f f f f 62 f f f 63 52 53 54 55 56 57 58 59 60 61 f f
-        f 0 f f f 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
-        22 23 24 25 f f f f f f 26 27 28 29 30 31 32 33 34 35 36 37 38 39
-        40 41 42 43 44 45 46 47 48 49 50 51
-    } nth ;
-
-: encode3 ( seq -- seq )
-    be> 4 [ 3 swap - -6 * shift HEX: 3f bitand ch>base64 ] map-with ;
-
-: decode4 ( str -- str )
-    [ base64>ch ] map 0 [ swap 6 shift bitor ] reduce 3 >be ;
-
-: >base64-rem ( str -- str )
-    [ 3 0 pad-right encode3 ] keep length 1+ head 4 CHAR: = pad-right ;
-
-IN: crypto
-: >base64 ( str -- str )
-    #! cut string into two pieces, convert 3 bytes at a time
-    #! pad string with = when not enough bits
-    [ length dup 3 mod - ] keep cut swap
-    [
-        3 group [ encode3 % ] each
-        dup empty? [ drop ] [ >base64-rem % ] if
-    ] "" make ;
-
-: base64> ( str -- str )
-    #! input length must be a mulitple of 4
-    [
-        [ 4 group [ decode4 % ] each ] keep [ CHAR: = = not ] count-end 
-    ] SBUF" " make swap [ dup pop* ] times >string ;
-
index ad8047f85452b2b74731e820d1e65cee931dda05..7ec605a856838ae936aa14c1716d6b9f2bee56aa 100644 (file)
@@ -5,7 +5,6 @@ PROVIDE: contrib/crypto
 
     "common.factor"
     "timing.factor"
-    "base64.factor"
     "barrett.factor"
     "montgomery.factor"
     "random.factor"
@@ -32,7 +31,6 @@ PROVIDE: contrib/crypto
     "test/md5.factor"
     "test/sha1.factor"
     "test/sha2.factor"
-    "test/base64.factor"
     "test/miller-rabin.factor"
     "test/crc32.factor"
     "test/rsa.factor"
diff --git a/contrib/crypto/test/base64.factor b/contrib/crypto/test/base64.factor
deleted file mode 100644 (file)
index eedbaea..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-USING: kernel math test namespaces crypto ;
-
-[ "abcdefghijklmnopqrstuvwxyz" ] [ "abcdefghijklmnopqrstuvwxyz" >base64 base64> ] unit-test
-[ "" ] [ "" >base64 base64> ] unit-test
-[ "a" ] [ "a" >base64 base64> ] unit-test
-[ "ab" ] [ "ab" >base64 base64> ] unit-test
-[ "abc" ] [ "abc" >base64 base64> ] unit-test
-