lib/crypto: Explode crypto.nit into package
authorPhilippe Pepos Petitclerc <ppeposp@gmail.com>
Sat, 14 May 2016 14:59:08 +0000 (10:59 -0400)
committerPhilippe Pepos Petitclerc <ppeposp@gmail.com>
Tue, 24 May 2016 15:51:00 +0000 (11:51 -0400)
Basic ciphers and utils are in basic_ciphers.nit
XOR-focused algorithms are in xor_ciphers.nit

Signed-off-by: Philippe Pepos Petitclerc <ppeposp@gmail.com>

lib/crypto/basic_ciphers.nit [moved from lib/crypto.nit with 93% similarity]
lib/crypto/crypto.nit [new file with mode: 0644]
lib/crypto/package.ini [moved from lib/crypto.ini with 89% similarity]
lib/crypto/xor_ciphers.nit [new file with mode: 0644]

similarity index 93%
rename from lib/crypto.nit
rename to lib/crypto/basic_ciphers.nit
index 0b52c99..e4a133c 100644 (file)
@@ -12,8 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Mix of all things cryptography-related
-module crypto
+# Basic cryptographic ciphers and utilities.
+module basic_ciphers
 
 redef class Char
        # Rotates self of `x`
@@ -157,22 +157,6 @@ redef class Text
 end
 
 redef class Bytes
-
-       # Returns `self` xored with `key`
-       #
-       # The key is cycled through until the `self` has been completely xored.
-       #
-       #     assert "goodmorning".to_bytes.xorcipher(" ".to_bytes) == "GOODMORNING".bytes
-       fun xorcipher(key: Bytes): Bytes do
-               var xored = new Bytes.with_capacity(self.length)
-
-               for i in self.length.times do
-                       xored.add(self[i] ^ key[i % key.length])
-               end
-
-               return xored
-       end
-
        # Computes the edit/hamming distance of two sequences of bytes.
        #
        #     assert "this is a test".to_bytes.hamming_distance("wokka wokka!!!".bytes) == 37
@@ -189,7 +173,6 @@ redef class Bytes
                end
                return diff
        end
-
 end
 
 redef class Int
diff --git a/lib/crypto/crypto.nit b/lib/crypto/crypto.nit
new file mode 100644 (file)
index 0000000..4709403
--- /dev/null
@@ -0,0 +1,19 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Mix of all things cryptography-related
+module crypto
+
+import basic_ciphers
+import xor_ciphers
similarity index 89%
rename from lib/crypto.ini
rename to lib/crypto/package.ini
index e8b4cf1..24f6b14 100644 (file)
@@ -6,6 +6,6 @@ license=Apache-2.0
 [upstream]
 browse=https://github.com/nitlang/nit/tree/master/lib/crypto.nit
 git=https://github.com/nitlang/nit.git
-git.directory=lib/crypto.nit
+git.directory=lib/crypto/crypto.nit
 homepage=http://nitlanguage.org
 issues=https://github.com/nitlang/nit/issues
diff --git a/lib/crypto/xor_ciphers.nit b/lib/crypto/xor_ciphers.nit
new file mode 100644 (file)
index 0000000..fefae4b
--- /dev/null
@@ -0,0 +1,33 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# XOR oriented cryptographic ciphers and utilities.
+module xor_ciphers
+
+redef class Bytes
+       # Returns `self` xored with `key`
+       #
+       # The key is cycled through until the `self` has been completely xored.
+       #
+       #     assert "goodmorning".to_bytes.xorcipher(" ".to_bytes) == "GOODMORNING".bytes
+       fun xorcipher(key: Bytes): Bytes do
+               var xored = new Bytes.with_capacity(self.length)
+
+               for i in self.length.times do
+                       xored.add(self[i] ^ key[i % key.length])
+               end
+
+               return xored
+       end
+end