Example #1
0
func main() {
	//Initalize our ciphertext
	c := "jnfcztiecytrtkxbrvwgoxjvbuyducvsridemeatptnxxouhkxkhosujeezvwukwoqpekfyrvojliwojonvxijzgrjusxehs otx"
	//Encode our ciphertext
	i := coding.Encode(c)
	//make the key slice
	k := make([]int, 7)
	//Since the ordering doesn't matter because n-c-v=n-v-c
	//We can decrypt everything with the Caesar cipher first
	//We check all possible caesar ciphers. then visually inspect for english visually.
	//When I wrote this I wasn't sure it was safe to assume caeser was always a shift by 3 as most of what I saw when I googled to double check was using it more generally as simple shift ciphers.
	for j := 0; j < 27; j++ {
		temp := shift(i, j)
		//Because we know some of the format of the message we can assume that k[0] will decrypt c[7]  to ' '
		//So we can just hardcode the value.
		//After we know one decrpytion, it is simple to decrypt each key based on our knowledge of the key permutation.
		//phi = [5, 6, 4, 2, 1, 3, 0]

		k[0] = (temp[7] - 26 + 27) % 27 //assume That k[0] will decrypt a ' '
		k[5] = (temp[0] - k[0] + 27) % 27
		k[3] = (temp[5] - k[5] + 27) % 27
		k[2] = (temp[3] - k[3] + 27) % 27
		k[4] = (temp[2] - k[2] + 27) % 27
		k[1] = (temp[4] - k[4] + 27) % 27
		k[6] = (temp[1] - k[1] + 27) % 27
		if temp[6]-k[6] == k[0] { //Verify that our assumption is correct

			fmt.Println("Good")
		}
		temp = decryptV(temp, k)

		fmt.Println(j, (temp[7]-26+27)%27, coding.Decode(temp))
	}

}
Example #2
0
func shift(base []rune, shift int) string {
	r := make([]int, len(base))
	//Encode the string so that shifting is simple
	s := coding.Encode(string(base))
	for i, k := range s {
		//i is the index, k is s[i]
		r[i] = (k + shift) % 27
	}
	//Decode the shifted string while returning i.
	return coding.Decode(r)
}
Example #3
0
func main() {
	//I think this is pretty self explanatory (s is a string, but you probably are used to this from python)
	s := "qualitatively"
	//coding.Encode returns an int slice, which is basically just an array that can be resized.
	i := coding.Encode(s)
	fmt.Println(i)
	//Initalize c as an int slice.
	c := []int{19, 7, 4, 26, 18, 4, 2, 17, 4, 19, 26, 22, 14, 17, 3, 26, 8, 18, 26, 1, 4, 11, 0, 1, 14, 17}
	//decode, which returns a string
	i2 := coding.Decode(c)
	fmt.Println(i2)

}
Example #4
0
func main() {
	//initialize x with our seed values
	x := []int{341, 817, 38, 471, 50, 277, 43, 491, 796, 812}
	//Initialize c with our ciphertext
	c := []int{346, 825, 55, 489, 69, 303, 60, 511, 807, 816, 299, 556, 142, 165, 459, 605, 76, 491, 997, 182, 144, 548, 991, 788, 222, 584, 410, 439, 403, 755, 986, 91, 990, 719, 833, 715, 611, 890, 78, 436, 63, 220, 32, 32, 49, 865, 909, 420, 60}
	for i, k := range c {
		//Decode our ciphertext
		c[i] = (P + k - x[0]) % P //Add P to make sure it stays positive
		//Increment our shift register
		x = shiftReg(x)
	}
	fmt.Println(coding.Decode(c))

}