Skip to content

Latest commit

 

History

History
 
 

re-fanoGo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

fanoGo

Idea

Implents fano with golang. The code will read your ascii input, convert it to strings of '0' and '1' and then decode with fano. fano code book is generated by the corpus.txt. If the decode result is equal with the given string(essay), you will get the flag. Both the corpus and essay is from Winston, Churchill.

Solve

You could run it and find the codebook in memory or reverse it from main_main. Don't reverse the functions in package like "fmt_Println", just look up the go manual. Impletes the binary-string function use biu I have write a encode funtions in fano.go, and there is a commentted snippet to encode the essay string , send the key and you will get the flag.

    cipher_result := F.Encode(essay)
    fmt.Println(cipher_result)

    f1, err1 := os.Create("key.txt")
    if err1 != nil {
        fmt.Print(err1)
    }
    defer f1.Close()

    n, _ := f1.WriteString(cipher_result)
    fmt.Printf("write %d bytes\n", n)
func Str2Bytes(cipher string) string{
    for len(cipher)%8 != 0{
        cipher += "0"
    }
    Bytes := ""
    for p:=0; p<len(cipher); p+=8{
        var a byte
        biu.ReadBinaryString(cipher[p:p+8], &a)
        Bytes+=string(a)

    }
    // for _,x :=range Bytes{
    //  fmt.Println(byte(x))
    // }
    return Bytes

}
func (f *Fano) Encode(plain string) string {
    cipher := ""
    for  i:=0; i< len(plain); i++{
      cipher += f.codebook[uint8(plain[i])].code
    }
    return Str2Bytes(cipher)
}