100% golint

This commit is contained in:
Derek McQuay 2016-03-11 23:31:26 -08:00
parent 5da34d3544
commit 878a06980c
3 changed files with 14 additions and 3 deletions

View File

@ -75,12 +75,13 @@ var rcon = []byte{0x00, // rcon[] is 1-based, so the first entry is just a place
0xE8, 0xCB, 0x8D, 0xE8, 0xCB, 0x8D,
} }
// renamed []byte type for simplicity //Block renamed []byte type for simplicity
type Block []byte type Block []byte
var keyexpanded []Block var keyexpanded []Block
var key Block var key Block
//ToString writes []Block to a string in ascii form
func ToString(all []Block, keysize int, k Block, decrypt bool) string { func ToString(all []Block, keysize int, k Block, decrypt bool) string {
final := "" final := ""
for _, bl := range all { for _, bl := range all {
@ -95,6 +96,7 @@ func ToString(all []Block, keysize int, k Block, decrypt bool) string {
return final return final
} }
//ToHex writes []Block to a string in hex form
func ToHex(all []Block, keysize int, k Block, decrypt bool) string { func ToHex(all []Block, keysize int, k Block, decrypt bool) string {
final := "" final := ""
for _, bl := range all { for _, bl := range all {
@ -111,6 +113,7 @@ func ToHex(all []Block, keysize int, k Block, decrypt bool) string {
return final return final
} }
//BlockGen helps create []Block from incoming string
func BlockGen(arg string) []Block { func BlockGen(arg string) []Block {
all := []Block{} all := []Block{}
b := Block{} b := Block{}
@ -131,7 +134,7 @@ func BlockGen(arg string) []Block {
return all return all
} }
//performs AES cipher //Cipher performs AES cipher
func Cipher(cur Block, bit int, incomingKey Block) Block { func Cipher(cur Block, bit int, incomingKey Block) Block {
if len(cur) != 16 { if len(cur) != 16 {
missing := 16 - len(cur) missing := 16 - len(cur)
@ -191,7 +194,7 @@ func Cipher(cur Block, bit int, incomingKey Block) Block {
return cur return cur
} }
//inverse AES cipher //InvCipher inverse AES cipher
func InvCipher(cur Block, bit int, incomingKey Block) Block { func InvCipher(cur Block, bit int, incomingKey Block) Block {
if len(cur) != 16 { if len(cur) != 16 {
missing := 16 - len(cur) missing := 16 - len(cur)

View File

@ -6,12 +6,14 @@ import (
"log" "log"
) )
//KeyJSON is a letter to letter mapping key
type KeyJSON struct { type KeyJSON struct {
Key map[string]string `json:"key"` Key map[string]string `json:"key"`
} }
var k = KeyJSON{} var k = KeyJSON{}
//ReadConfig reads a json file containing key map
func ReadConfig(file string) { func ReadConfig(file string) {
dat, err := ioutil.ReadFile(file) dat, err := ioutil.ReadFile(file)
if err != nil { if err != nil {
@ -21,6 +23,7 @@ func ReadConfig(file string) {
k.Key[" "] = " " // keep spaces alive k.Key[" "] = " " // keep spaces alive
} }
//Substitution performs Substitution cipher based on key
func Substitution(input string) string { func Substitution(input string) string {
inputSlice := []string{} inputSlice := []string{}
output := "" output := ""

View File

@ -2,6 +2,7 @@ package psyfer
import "math/rand" import "math/rand"
//TransposeRandom randomly transposes string
func TransposeRandom(input string) string { func TransposeRandom(input string) string {
shuffle := "" shuffle := ""
list := rand.Perm(len(input)) list := rand.Perm(len(input))
@ -11,6 +12,7 @@ func TransposeRandom(input string) string {
return shuffle return shuffle
} }
//TransposeRailFence performs railfence transpose
func TransposeRailFence(input string) string { func TransposeRailFence(input string) string {
rf := "" rf := ""
for i := 0; i < len(input); i += 2 { for i := 0; i < len(input); i += 2 {
@ -22,6 +24,7 @@ func TransposeRailFence(input string) string {
return rf return rf
} }
//TransposeSplit performs split transpose
func TransposeSplit(input string) string { func TransposeSplit(input string) string {
split := "" split := ""
length := len(input) length := len(input)
@ -40,6 +43,7 @@ func TransposeSplit(input string) string {
return split return split
} }
//DeTransposeRailFence performs inverse railfence
func DeTransposeRailFence(input string) string { func DeTransposeRailFence(input string) string {
derf := "" derf := ""
length := len(input) length := len(input)
@ -58,6 +62,7 @@ func DeTransposeRailFence(input string) string {
return derf return derf
} }
//DeTransposeSplit performs inverse split
func DeTransposeSplit(input string) string { func DeTransposeSplit(input string) string {
desplit := "" desplit := ""
if len(input)%2 == 0 { if len(input)%2 == 0 {