“Go” And Find Gold Bug

I have a deep love of cracking ciphers, and I love the Go programming language, so let’s “Go” in hunt of gold bug.

“Go” And Find Gold Bug

I have a deep love of cracking ciphers, and I love the Go programming language, so let’s “Go” in hunt of gold bug.

The Gold-Bug cipher has included in a short story by Edgar Allan Poe and which was published in 1843. It tells the tail of William Legrand and how he was bitten by a gold-colored bug. In the book he writes:

Here Legrand, having re-heated the parchment, submitted it to my inspection. The following characters were rudely traced, in a red tint, between the death's-head and the goat:
53‡‡†305))6*;4826)4‡.)4‡);806*;48†8¶60))85;1‡(;:‡*8†83(88)5*†;
46(;88*96*?;8)*‡(;485);5*†2:*‡(;4956*2(5*—4)8¶8*;4069285);)6†8
)4‡‡;1(‡9;48081;8:8‡1;48†85;4)485†528806*81(‡9;48;(88;4(‡?
34;48)4‡;161;:188;‡?;

The mapping is fairly easy to discover, as we can do a simple frequency analysis. First we can write a Go program to analyse the frequencies:

This gives:

5 12
2 5
- 1
T 8
8 33
1 8
3 4
4 19
6 11
, 0
7 0
0 6
9 5
* 13
I 16
. 1
$ 0
( 10
) 16
; 26
? 3
P 2
] 0
C 0
: 4
[ 0

We can quickly see that “8” is the most common letter and our cipher becomes:

53‡‡†305))6*;4e26)4‡.)4‡);e06*;4e†e¶60))e5;1‡(;:‡*e†e3(ee)5*†;
46(;ee*96*?;e)*‡(;4e5);5*†2:*‡(;4956*2(5*—4)e¶e*;40692e5);)6†e
)4‡‡;1(‡9;4e0e1;e:e‡1;4e†e5;4)4e5†52ee06*e1(‡9;4e;(ee;4(‡?
34;4e)4‡;161;:1ee;‡?;

If we keep going, and looking matching the expected frequencies of letters, we get the following mapping:

abcdefghijklmnopqrstuvwxyz
52-†81346,709*‡.$();?¶]¢:[

This is translated as:

5 - A
3‡‡† - good
305)) - glass
6* - in
;48 - the

Finally we can write a Go program to covert back to standard English:

package main
import (
"fmt"
"strings"
)
func main() {
str:="53IIT305))6*;4826)4I.)4I);806*;48T8P60))85;1I(;:I*8T83(88)5*T;46(;88*96*?;8)*I(;485);5*T2:*I(;4956*2(5*-4)8P8*;4069285);)6T8)4II;1(I9;48081;8:8I1;48T85;4)485T528806*81(I9;48;(88;4(I?34;48)4I;161;:188;I?;"
chars:="52-T81346,709*I.$();?P]C:["
for i:=0; i<len(str);i++ {
c:=string(str[i])
val:=strings.Index(chars, c)
fmt.Printf("%c",val+65)

}
}

The output is then:

AGOODGLASSINTHEBISHOPSHOSTELINTHEDEVILSSEATFORTYONEDEGREESANDTHIRTEENMINUTESNORTHEASTANDBYNORTHMAINBRANCHSEVENTHLIMBEASTSIDESHOOTFROMTHELEFTEYEOFTHEDEATHSHEADABEELINEFROMTHETREETHROUGHTHESHOTFIFTYFEETOUT

The output is then:

A GOOD GLASS IN THE BISHOPS HOSTEL IN THE DEVILS SEAT FORTY ONE DEGREES AND THIRTEEN MINUTES NORTH EAST AND BY NORTH MAIN BRANCH SEVENTH LIM BEAST SIDE SHOOT FROM THE LEFT EYEOFTHEDEATHSHEADABEELINEFROMTHETREETHROUGHTHESHOTFIFTYFEETOUT

Here is a sample cipher for you:

and: