예제 #1
0
package package2

import (
	"bitbucket.org/jkingry/matsano/cmd"
	"bitbucket.org/jkingry/matsano/encoding"
	"bitbucket.org/jkingry/matsano/package1"
	"crypto/aes"
	"fmt"
)

var Commands *cmd.Command = cmd.NewCommand("p2", "Package 2 commands")

func init() {
	var blockSize int
	pad := Commands.Add("pad", "[input]")
	pad.Flags.IntVar(&blockSize, "blockSize", 20, "block size")
	pad.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Ascii)
		input := encoding.In.Decode(cmd.GetInput(args, 0))
		fmt.Print(encoding.Out.Encode(Pkcs7_pad(blockSize, input)))
	}

	unpad := Commands.Add("unpad", "[input]")
	unpad.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Ascii)
		input := encoding.In.Decode(cmd.GetInput(args, 0))
		fmt.Print(encoding.Out.Encode(Pkcs7_unpad(input)))
	}

	encrypt := Commands.Add("encrypt", "[key] [iv] [input]")
	encrypt.Command = func(args []string) {
예제 #2
0
			delete(h, k)
		}
	}
}

func (h Histogram) Normalize() {
	sum := 0.0
	for _, v := range h {
		sum += v
	}
	for k, v := range h {
		h[k] = v / sum
	}
}

var Commands *cmd.Command = cmd.NewCommand("histogram", "histogram commands")

func init() {
	create := Commands.Add("create", "[input]...")
	create.Command = func(args []string) {
		h := Make()
		for i := 0; i < len(args); i++ {
			hf := New([]byte(cmd.GetInput(args, i)))
			h.Add(hf)
		}
		if len(args) == 0 {
			hf := New([]byte(cmd.GetInput(args, 0)))
			h.Add(hf)
		}

		fmt.Print(h)
예제 #3
0
package package1

import (
	"bitbucket.org/jkingry/matsano/cmd"
	"bitbucket.org/jkingry/matsano/encoding"
	"fmt"
	"os"
)

var Commands *cmd.Command = cmd.NewCommand("p1", "Package 1 commands")

func init() {
	translate := func(decode func(string) []byte, encode func([]byte) string) func([]string) {
		return func(args []string) {
			data := decode(cmd.GetInput(args, 0))
			fmt.Print(encode(data))
		}
	}

	for inputName, inputEncoding := range encoding.Encodings {
		translateCommand := Commands.Add(inputName, "Translate from "+inputName)
		for outputName, outputEncoding := range encoding.Encodings {
			if outputName == inputName {
				continue
			}
			translateCommand.Add(outputName, "to "+outputName).Command = translate(inputEncoding.Decode, outputEncoding.Encode)
		}
	}

	xor := Commands.Add("xor", "[key] [input]")
	xor.Command = func(args []string) {