commit 70420c9c73cdd9b9439fb353686b6e5b932f094d
parent 90c6a197e5b4c24bd9a4ee0510e0f317b412a0a9
Author: sin <sin@2f30.org>
Date: Tue, 30 Apr 2013 15:13:42 +0100
add bdec and benc
Diffstat:
4 files changed, 110 insertions(+), 1 deletion(-)
diff --git a/build b/build
@@ -4,3 +4,5 @@ export GOPATH=$PWD
go get "code.google.com/p/go.crypto/blowfish"
go get "code.google.com/p/go9p/p"
go build -o src/kunt/kunt -v kunt
+go build -o src/bdec/bdec -v bdec
+go build -o src/benc/benc -v benc
diff --git a/src/bdec/bdec.go b/src/bdec/bdec.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "code.google.com/p/go.crypto/blowfish"
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "os"
+)
+
+func usage() {
+ fmt.Fprintf(os.Stderr, "usage: %s <pass> <encrypted-file>\n",
+ os.Args[0])
+ os.Exit(2)
+}
+
+func decryptBuf(c *blowfish.Cipher, a []byte) []byte {
+ pt := make([]byte, len(a))
+ for i := 0; i < len(a); i += blowfish.BlockSize {
+ c.Decrypt(pt[i:i+blowfish.BlockSize],
+ a[i:i+blowfish.BlockSize])
+ }
+ return pt
+}
+
+func main() {
+ log.SetPrefix("bdec: ")
+ flag.Usage = usage
+ flag.Parse()
+
+ args := flag.Args()
+ if len(args) < 2 {
+ usage()
+ }
+
+ c, err := blowfish.NewCipher([]byte(args[0]))
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ b, err := ioutil.ReadFile(args[1])
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Fprintf(os.Stdout, "%s", decryptBuf(c, b))
+}
diff --git a/src/benc/benc.go b/src/benc/benc.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "code.google.com/p/go.crypto/blowfish"
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "os"
+)
+
+func usage() {
+ fmt.Fprintf(os.Stderr, "usage: %s <pass> <file>\n",
+ os.Args[0])
+ os.Exit(2)
+}
+
+func encryptBuf(c *blowfish.Cipher, a []byte) []byte {
+ padded := a
+ diff := len(a) % blowfish.BlockSize
+ if diff != 0 {
+ diff = blowfish.BlockSize - diff
+ }
+ for i := 0; i < diff; i++ {
+ padded = append(padded, byte(0x0))
+ }
+ ct := make([]byte, len(padded))
+ for i := 0; i < len(a); i += blowfish.BlockSize {
+ if i+blowfish.BlockSize > len(a) {
+ c.Encrypt(ct[i:], padded[i:])
+ return ct
+ }
+ c.Encrypt(ct[i:i+blowfish.BlockSize],
+ padded[i:i+blowfish.BlockSize])
+ }
+ return ct
+}
+
+func main() {
+ log.SetPrefix("benc: ")
+ flag.Usage = usage
+ flag.Parse()
+
+ args := flag.Args()
+ if len(args) < 2 {
+ usage()
+ }
+
+ c, err := blowfish.NewCipher([]byte(args[0]))
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ b, err := ioutil.ReadFile(args[1])
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Fprintf(os.Stdout, "%s", encryptBuf(c, b))
+}
diff --git a/src/mapfs/mapfs.go b/src/mapfs/mapfs.go
@@ -82,7 +82,6 @@ func NewEncryptedMapfs(name string, path string, prefix string, key string) *Map
encrypt: true,
cipher: c,
}
-
}
// Sync dirty entries to disk