{"id":650,"date":"2020-05-12T11:23:34","date_gmt":"2020-05-12T11:23:34","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=650"},"modified":"2020-05-12T13:23:49","modified_gmt":"2020-05-12T13:23:49","slug":"golang-smiplecipher-v2-0","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2020\/05\/12\/golang-smiplecipher-v2-0\/","title":{"rendered":"GoLang: SmipleCipher v2.0"},"content":{"rendered":"<p>So continuing from the last <a href=\"https:\/\/blog.samarthya.me\/wps\/2020\/05\/11\/golang-simplecipher\/\">blog<\/a> where I wrote a crude version of SimpleCipher and was inclined on removing the duplicate code, here I am with the improved version.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-medium wp-image-647\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2020\/05\/SimpleCipher-300x127.png\" alt=\"\" width=\"300\" height=\"127\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2020\/05\/SimpleCipher-300x127.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2020\/05\/SimpleCipher.png 320w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3>Handy links<\/h3>\n<ul>\n<li>`<a href=\"https:\/\/golang.org\/pkg\/fmt\/\">fmt`<\/a> package<\/li>\n<li>`<a href=\"https:\/\/golang.org\/pkg\/strings\/\">strings<\/a>` package.<\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\">Defining <code>types<\/code><\/h2>\n\n\n\n<p>While I compiled and unit tested code the general feeling was what can be optimized.<\/p>\n\n\n\n<p>The obvious choice was to move away from the distance &amp; key and use something common to have reduced code.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>transformWithDistance<\/li><li>transformWithString<\/li><\/ul>\n\n\n\n<p>These functions had to go.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Vigenere Stores the key\ntype Vigenere struct {\n\tkey string\n}<\/code><\/pre>\n\n\n\n<p>The new struct I defined was intended to store only key, and when the distance (for int) is being supplied I will use this to find the <code>char<\/code> that I can use as key. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Example: <\/p><p>If distance is 3 the key becomes <code>d<\/code> and if it 2 it is <code>b<\/code><\/p><\/blockquote>\n\n\n\n<p>Using this as the building block I defined the new rotation function that will manage the encode\/decode logic.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func mapChar(s rune, r int32) (e rune) {\n\tswitch {\n\tcase s &lt; 'a'-r:\n\t\te = s + 26 + r\n\tcase s > 'z'-r:\n\t\te = (s - 26 + r)\n\tdefault:\n\t\te = s + r\n\t}\n\treturn e\n}<\/code><\/pre>\n\n\n\n<p>The flow was simple<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You input the char\/rune to encode or decode<\/li><li>Use the key rune that will be used to displace the original rune.<\/li><li>Get the resulting rune<\/li><\/ul>\n\n\n\n<p>Accordingly the other structs also changed<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ NewCaesar Object that implements the interface Cipher\nfunc NewCaesar() Cipher {\n\treturn Vigenere{key: \"d\"}\n}\n\n\/\/ NewShift Object that implements the interface Cipher\nfunc NewShift(distance int) Cipher {\n\t\/\/ Corner case when of 0, 26, -26\n\tif distance &lt;= -26 || distance >= 26 {\n\t\treturn nil\n\t}\n\treturn NewVigenere(string(mapChar('a', int32(distance))))\n}\n\n\/\/ NewVigenere Object that implements the interface Cipher\nfunc NewVigenere(k string) Cipher {\n\n\tif regexp.MustCompile(`&#91;^a-z]`).MatchString(k) || regexp.MustCompile(`^a*$`).MatchString(k) {\n\t\treturn nil\n\t}\n\n\treturn Vigenere{key: k}\n}<\/code><\/pre>\n\n\n\n<p>As evident now it is just key that is used for default case the char &#8211; <code>d<\/code> is being used and in other cases we map the input distance to the appropriate single letter key using the function <code>mapChar<\/code>.<\/p>\n\n\n\n<p>The strip string function remained the same (just a new and fancy name)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ stripString replace all the other elements\nfunc stripString(s string) (o string) {\n\to = RegularExp.ReplaceAllString(s, \"\")\n\tlog.Printf(\" String: %s\", o)\n\to = strings.ToLower(o)\n\treturn\n}<\/code><\/pre>\n\n\n\n<p>and the Encode &amp; Decode became as under.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Encode Implements the interface Cipher\nfunc (e Vigenere) Encode(s string) (o string) {\n\n\tvar sb strings.Builder\n\n\to = \"\"\n\ts = stripString(s)\n\n\tif s == \"\" || len(s) &lt;= 0 {\n\t\treturn\n\t}\n\n\tlog.Printf(\" Encode: %s\", s)\n\t\/\/ Iterate throught the runes\n\n\tfor i, m := range s {\n\t\tnewChar := mapChar(m, int32(e.key&#91;i%len(e.key)]-'a'))\n\t\tfmt.Fprintf(&amp;sb, \"%c\", newChar)\n\t}\n\n\to = sb.String()\n\tlog.Printf(\" Encoded: %s\", o)\n\treturn\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Decode decides the encrypted string\nfunc (e Vigenere) Decode(s string) (o string) {\n\tvar sb strings.Builder\n\n\to = \"\"\n\n\tlog.Printf(\" Decode: %s\", s)\n\n\tif s == \"\" || len(s) &lt;= 0 {\n\t\treturn\n\t}\n\n\tfor i, m := range s {\n\t\tnewChar := mapChar(m, -int32(e.key&#91;i%len(e.key)]-'a'))\n\t\tfmt.Fprintf(&amp;sb, \"%c\", newChar)\n\t}\n\n\to = sb.String()\n\tlog.Printf(\" Decoded: %s\", o)\n\n\treturn\n}<\/code><\/pre>\n\n\n\n<p>I have used few packages as evident from the code.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>fmt<\/li><li>log<\/li><li>strings<\/li><\/ul>\n\n\n\n<p>A sample go test results in <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go test\n2020\/05\/12 16:30:23  String: iamapandabear\n2020\/05\/12 16:30:23  Encode: iamapandabear\n2020\/05\/12 16:30:23  Encoded: ldpdsdqgdehdu\n2020\/05\/12 16:30:23  String: programmingisawesome\n2020\/05\/12 16:30:23  Encode: programmingisawesome\n2020\/05\/12 16:30:23  Encoded: surjudpplqjlvdzhvrph\n2020\/05\/12 16:30:23  String: todayisholiday\n2020\/05\/12 16:30:23  Encode: todayisholiday\n2020\/05\/12 16:30:23  Encoded: wrgdblvkrolgdb\n2020\/05\/12 16:30:23  String: venividivici\n2020\/05\/12 16:30:23  Encode: venividivici\n2020\/05\/12 16:30:23  Encoded: yhqlylglylfl\n2020\/05\/12 16:30:23  String: Gogogophers\n2020\/05\/12 16:30:23  Encode: gogogophers\n2020\/05\/12 16:30:23  Encoded: jrjrjrskhuv\n2020\/05\/12 16:30:23  Decode: jrjrjrskhuv\n2020\/05\/12 16:30:23  Decoded: gogogophers\n2020\/05\/12 16:30:23  String: Iamapandabear\n2020\/05\/12 16:30:23  Encode: iamapandabear\n2020\/05\/12 16:30:23  Encoded: ldpdsdqgdehdu\n2020\/05\/12 16:30:23  Decode: ldpdsdqgdehdu\n2020\/05\/12 16:30:23  Decoded: iamapandabear\n2020\/05\/12 16:30:23  String: ProgrammingisAWESOME\n2020\/05\/12 16:30:23  Encode: programmingisawesome\n2020\/05\/12 16:30:23  Encoded: surjudpplqjlvdzhvrph\n2020\/05\/12 16:30:23  Decode: surjudpplqjlvdzhvrph\n2020\/05\/12 16:30:23  Decoded: programmingisawesome\n2020\/05\/12 16:30:23  String: todayisholiday\n2020\/05\/12 16:30:23  Encode: todayisholiday\n2020\/05\/12 16:30:23  Encoded: wrgdblvkrolgdb\n2020\/05\/12 16:30:23  Decode: wrgdblvkrolgdb\n2020\/05\/12 16:30:23  Decoded: todayisholiday\n2020\/05\/12 16:30:23  String: TwasthenightbeforeChristmas\n2020\/05\/12 16:30:23  Encode: twasthenightbeforechristmas\n2020\/05\/12 16:30:23  Encoded: wzdvwkhqljkwehiruhfkulvwpdv\n2020\/05\/12 16:30:23  Decode: wzdvwkhqljkwehiruhfkulvwpdv\n2020\/05\/12 16:30:23  Decoded: twasthenightbeforechristmas\n2020\/05\/12 16:30:23  String: venividivici\n2020\/05\/12 16:30:23  Encode: venividivici\n2020\/05\/12 16:30:23  Encoded: yhqlylglylfl\n2020\/05\/12 16:30:23  Decode: yhqlylglylfl\n2020\/05\/12 16:30:23  Decoded: venividivici\n2020\/05\/12 16:30:23  String: \n2020\/05\/12 16:30:23  Decode: \n2020\/05\/12 16:30:23  String: \n2020\/05\/12 16:30:23  Decode: \n2020\/05\/12 16:30:23  String: Gogogophers\n2020\/05\/12 16:30:23  Encode: gogogophers\n2020\/05\/12 16:30:23  Encoded: jrjrjrskhuv\n2020\/05\/12 16:30:23  Decode: jrjrjrskhuv\n2020\/05\/12 16:30:23  Decoded: gogogophers\n2020\/05\/12 16:30:23  String: Iamapandabear\n2020\/05\/12 16:30:23  Encode: iamapandabear\n2020\/05\/12 16:30:23  Encoded: ldpdsdqgdehdu\n2020\/05\/12 16:30:23  Decode: ldpdsdqgdehdu\n2020\/05\/12 16:30:23  Decoded: iamapandabear\n2020\/05\/12 16:30:23  String: ProgrammingisAWESOME\n2020\/05\/12 16:30:23  Encode: programmingisawesome\n2020\/05\/12 16:30:23  Encoded: surjudpplqjlvdzhvrph\n2020\/05\/12 16:30:23  Decode: surjudpplqjlvdzhvrph\n2020\/05\/12 16:30:23  Decoded: programmingisawesome\n2020\/05\/12 16:30:23  String: todayisholiday\n2020\/05\/12 16:30:23  Encode: todayisholiday\n2020\/05\/12 16:30:23  Encoded: wrgdblvkrolgdb\n2020\/05\/12 16:30:23  Decode: wrgdblvkrolgdb\n2020\/05\/12 16:30:23  Decoded: todayisholiday\n2020\/05\/12 16:30:23  String: TwasthenightbeforeChristmas\n2020\/05\/12 16:30:23  Encode: twasthenightbeforechristmas\n2020\/05\/12 16:30:23  Encoded: wzdvwkhqljkwehiruhfkulvwpdv\n2020\/05\/12 16:30:23  Decode: wzdvwkhqljkwehiruhfkulvwpdv\n2020\/05\/12 16:30:23  Decoded: twasthenightbeforechristmas\n2020\/05\/12 16:30:23  String: venividivici\n2020\/05\/12 16:30:23  Encode: venividivici\n2020\/05\/12 16:30:23  Encoded: yhqlylglylfl\n2020\/05\/12 16:30:23  Decode: yhqlylglylfl\n2020\/05\/12 16:30:23  Decoded: venividivici\n2020\/05\/12 16:30:23  String: \n2020\/05\/12 16:30:23  Decode: \n2020\/05\/12 16:30:23  String: \n2020\/05\/12 16:30:23  Decode: \n2020\/05\/12 16:30:23  String: THEENEMYISNEAR\n2020\/05\/12 16:30:23  Encode: theenemyisnear\n2020\/05\/12 16:30:23  Encoded: qebbkbjvfpkbxo\n2020\/05\/12 16:30:23  Decode: qebbkbjvfpkbxo\n2020\/05\/12 16:30:23  Decoded: theenemyisnear\n2020\/05\/12 16:30:23  String: SPIESSENDSECRETMESSAGES\n2020\/05\/12 16:30:23  Encode: spiessendsecretmessages\n2020\/05\/12 16:30:23  Encoded: pmfbppbkapbzobqjbppxdbp\n2020\/05\/12 16:30:23  Decode: pmfbppbkapbzobqjbppxdbp\n2020\/05\/12 16:30:23  Decoded: spiessendsecretmessages\n2020\/05\/12 16:30:23  String: THOMASJEFFERSONDESIGNEDASUBSTITUTIONCIPHER\n2020\/05\/12 16:30:23  Encode: thomasjeffersondesignedasubstitutioncipher\n2020\/05\/12 16:30:23  Encoded: qeljxpgbccboplkabpfdkbaxprypqfqrqflkzfmebo\n2020\/05\/12 16:30:23  Decode: qeljxpgbccboplkabpfdkbaxprypqfqrqflkzfmebo\n2020\/05\/12 16:30:23  Decoded: thomasjeffersondesignedasubstitutioncipher\n2020\/05\/12 16:30:23  String: thequickbrownfoxjumpsoverthelazydog\n2020\/05\/12 16:30:23  Encode: thequickbrownfoxjumpsoverthelazydog\n2020\/05\/12 16:30:23  Encoded: qebnrfzhyoltkclugrjmplsboqebixwvald\n2020\/05\/12 16:30:23  Decode: qebnrfzhyoltkclugrjmplsboqebixwvald\n2020\/05\/12 16:30:23  Decoded: thequickbrownfoxjumpsoverthelazydog\n2020\/05\/12 16:30:23  String: ATTACKATDAWN\n2020\/05\/12 16:30:23  Encode: attackatdawn\n2020\/05\/12 16:30:23  Encoded: lxfopvefrnhr\n2020\/05\/12 16:30:23  Decode: lxfopvefrnhr\n2020\/05\/12 16:30:23  Decoded: attackatdawn\n2020\/05\/12 16:30:23  String: aaaaaaaaaa\n2020\/05\/12 16:30:23  Encode: aaaaaaaaaa\n2020\/05\/12 16:30:23  Encoded: abcdefghij\n2020\/05\/12 16:30:23  Decode: abcdefghij\n2020\/05\/12 16:30:23  Decoded: aaaaaaaaaa\n2020\/05\/12 16:30:23  String: zzzzzzzzzz\n2020\/05\/12 16:30:23  Encode: zzzzzzzzzz\n2020\/05\/12 16:30:23  Encoded: zabcdefghi\nC02Z45LYLVDR:Samarthya:simple-cipher> go test\n2020\/05\/12 16:46:26  String: iamapandabear\n2020\/05\/12 16:46:26  Encode: iamapandabear\n2020\/05\/12 16:46:26  Encoded: ldpdsdqgdehdu\n2020\/05\/12 16:46:26  String: programmingisawesome\n2020\/05\/12 16:46:26  Encode: programmingisawesome\n2020\/05\/12 16:46:26  Encoded: surjudpplqjlvdzhvrph\n2020\/05\/12 16:46:26  String: todayisholiday\n2020\/05\/12 16:46:26  Encode: todayisholiday\n2020\/05\/12 16:46:26  Encoded: wrgdblvkrolgdb\n2020\/05\/12 16:46:26  String: venividivici\n2020\/05\/12 16:46:26  Encode: venividivici\n2020\/05\/12 16:46:26  Encoded: yhqlylglylfl\n2020\/05\/12 16:46:26  String: Gogogophers\n2020\/05\/12 16:46:26  Encode: gogogophers\n2020\/05\/12 16:46:26  Encoded: jrjrjrskhuv\n2020\/05\/12 16:46:26  Decode: jrjrjrskhuv\n2020\/05\/12 16:46:26  Decoded: gogogophers\n2020\/05\/12 16:46:26  String: Iamapandabear\n2020\/05\/12 16:46:26  Encode: iamapandabear\n2020\/05\/12 16:46:26  Encoded: ldpdsdqgdehdu\n2020\/05\/12 16:46:26  Decode: ldpdsdqgdehdu\n2020\/05\/12 16:46:26  Decoded: iamapandabear\n2020\/05\/12 16:46:26  String: ProgrammingisAWESOME\n2020\/05\/12 16:46:26  Encode: programmingisawesome\n2020\/05\/12 16:46:26  Encoded: surjudpplqjlvdzhvrph\n2020\/05\/12 16:46:26  Decode: surjudpplqjlvdzhvrph\n2020\/05\/12 16:46:26  Decoded: programmingisawesome\n2020\/05\/12 16:46:26  String: todayisholiday\n2020\/05\/12 16:46:26  Encode: todayisholiday\n2020\/05\/12 16:46:26  Encoded: wrgdblvkrolgdb\n2020\/05\/12 16:46:26  Decode: wrgdblvkrolgdb\n2020\/05\/12 16:46:26  Decoded: todayisholiday\n2020\/05\/12 16:46:26  String: TwasthenightbeforeChristmas\n2020\/05\/12 16:46:26  Encode: twasthenightbeforechristmas\n2020\/05\/12 16:46:26  Encoded: wzdvwkhqljkwehiruhfkulvwpdv\n2020\/05\/12 16:46:26  Decode: wzdvwkhqljkwehiruhfkulvwpdv\n2020\/05\/12 16:46:26  Decoded: twasthenightbeforechristmas\n2020\/05\/12 16:46:26  String: venividivici\n2020\/05\/12 16:46:26  Encode: venividivici\n2020\/05\/12 16:46:26  Encoded: yhqlylglylfl\n2020\/05\/12 16:46:26  Decode: yhqlylglylfl\n2020\/05\/12 16:46:26  Decoded: venividivici\n2020\/05\/12 16:46:26  String: \n2020\/05\/12 16:46:26  Decode: \n2020\/05\/12 16:46:26  String: \n2020\/05\/12 16:46:26  Decode: \n2020\/05\/12 16:46:26  String: Gogogophers\n2020\/05\/12 16:46:26  Encode: gogogophers\n2020\/05\/12 16:46:26  Encoded: jrjrjrskhuv\n2020\/05\/12 16:46:26  Decode: jrjrjrskhuv\n2020\/05\/12 16:46:26  Decoded: gogogophers\n2020\/05\/12 16:46:26  String: Iamapandabear\n2020\/05\/12 16:46:26  Encode: iamapandabear\n2020\/05\/12 16:46:26  Encoded: ldpdsdqgdehdu\n2020\/05\/12 16:46:26  Decode: ldpdsdqgdehdu\n2020\/05\/12 16:46:26  Decoded: iamapandabear\n2020\/05\/12 16:46:26  String: ProgrammingisAWESOME\n2020\/05\/12 16:46:26  Encode: programmingisawesome\n2020\/05\/12 16:46:26  Encoded: surjudpplqjlvdzhvrph\n2020\/05\/12 16:46:26  Decode: surjudpplqjlvdzhvrph\n2020\/05\/12 16:46:26  Decoded: programmingisawesome\n2020\/05\/12 16:46:26  String: todayisholiday\n2020\/05\/12 16:46:26  Encode: todayisholiday\n2020\/05\/12 16:46:26  Encoded: wrgdblvkrolgdb\n2020\/05\/12 16:46:26  Decode: wrgdblvkrolgdb\n2020\/05\/12 16:46:26  Decoded: todayisholiday\n2020\/05\/12 16:46:26  String: TwasthenightbeforeChristmas\n2020\/05\/12 16:46:26  Encode: twasthenightbeforechristmas\n2020\/05\/12 16:46:26  Encoded: wzdvwkhqljkwehiruhfkulvwpdv\n2020\/05\/12 16:46:26  Decode: wzdvwkhqljkwehiruhfkulvwpdv\n2020\/05\/12 16:46:26  Decoded: twasthenightbeforechristmas\n2020\/05\/12 16:46:26  String: venividivici\n2020\/05\/12 16:46:26  Encode: venividivici\n2020\/05\/12 16:46:26  Encoded: yhqlylglylfl\n2020\/05\/12 16:46:26  Decode: yhqlylglylfl\n2020\/05\/12 16:46:26  Decoded: venividivici\n2020\/05\/12 16:46:26  String: \n2020\/05\/12 16:46:26  Decode: \n2020\/05\/12 16:46:26  String: \n2020\/05\/12 16:46:26  Decode: \n2020\/05\/12 16:46:26  String: THEENEMYISNEAR\n2020\/05\/12 16:46:26  Encode: theenemyisnear\n2020\/05\/12 16:46:26  Encoded: qebbkbjvfpkbxo\n2020\/05\/12 16:46:26  Decode: qebbkbjvfpkbxo\n2020\/05\/12 16:46:26  Decoded: theenemyisnear\n2020\/05\/12 16:46:26  String: SPIESSENDSECRETMESSAGES\n2020\/05\/12 16:46:26  Encode: spiessendsecretmessages\n2020\/05\/12 16:46:26  Encoded: pmfbppbkapbzobqjbppxdbp\n2020\/05\/12 16:46:26  Decode: pmfbppbkapbzobqjbppxdbp\n2020\/05\/12 16:46:26  Decoded: spiessendsecretmessages\n2020\/05\/12 16:46:26  String: THOMASJEFFERSONDESIGNEDASUBSTITUTIONCIPHER\n2020\/05\/12 16:46:26  Encode: thomasjeffersondesignedasubstitutioncipher\n2020\/05\/12 16:46:26  Encoded: qeljxpgbccboplkabpfdkbaxprypqfqrqflkzfmebo\n2020\/05\/12 16:46:26  Decode: qeljxpgbccboplkabpfdkbaxprypqfqrqflkzfmebo\n2020\/05\/12 16:46:26  Decoded: thomasjeffersondesignedasubstitutioncipher\n2020\/05\/12 16:46:26  String: thequickbrownfoxjumpsoverthelazydog\n2020\/05\/12 16:46:26  Encode: thequickbrownfoxjumpsoverthelazydog\n2020\/05\/12 16:46:26  Encoded: qebnrfzhyoltkclugrjmplsboqebixwvald\n2020\/05\/12 16:46:26  Decode: qebnrfzhyoltkclugrjmplsboqebixwvald\n2020\/05\/12 16:46:26  Decoded: thequickbrownfoxjumpsoverthelazydog\n2020\/05\/12 16:46:26  String: ATTACKATDAWN\n2020\/05\/12 16:46:26  Encode: attackatdawn\n2020\/05\/12 16:46:26  Encoded: lxfopvefrnhr\n2020\/05\/12 16:46:26  Decode: lxfopvefrnhr\n2020\/05\/12 16:46:26  Decoded: attackatdawn\n2020\/05\/12 16:46:26  String: aaaaaaaaaa\n2020\/05\/12 16:46:26  Encode: aaaaaaaaaa\n2020\/05\/12 16:46:26  Encoded: abcdefghij\n2020\/05\/12 16:46:26  Decode: abcdefghij\n2020\/05\/12 16:46:26  Decoded: aaaaaaaaaa\n2020\/05\/12 16:46:26  String: zzzzzzzzzz\n2020\/05\/12 16:46:26  Encode: zzzzzzzzzz\n2020\/05\/12 16:46:26  Encoded: zabcdefghi\n2020\/05\/12 16:46:26  Decode: zabcdefghi\n2020\/05\/12 16:46:26  Decoded: zzzzzzzzzz\n2020\/05\/12 16:46:26  String: Iamapandabear\n2020\/05\/12 16:46:26  Encode: iamapandabear\n2020\/05\/12 16:46:26  Encoded: qayaeaagaciai\n2020\/05\/12 16:46:26  Decode: qayaeaagaciai\n2020\/05\/12 16:46:26  Decoded: iamapandabear\n2020\/05\/12 16:46:26  String: DiffieHellman\n2020\/05\/12 16:46:26  Encode: diffiehellman\n2020\/05\/12 16:46:26  Encoded: gccwkixcltycv\n2020\/05\/12 16:46:26  Decode: gccwkixcltycv\n2020\/05\/12 16:46:26  Decoded: diffiehellman\n2020\/05\/12 16:46:26  String: cofFEE\n2020\/05\/12 16:46:26  Encode: coffee\n2020\/05\/12 16:46:26  Encoded: sugars\n2020\/05\/12 16:46:26  Decode: sugars\n2020\/05\/12 16:46:26  Decoded: coffee\nPASS\nok      cipher  0.021s<\/code><\/pre>\n\n\n\n<p>Source code available <a href=\"https:\/\/raw.githubusercontent.com\/samarthya\/goexercism\/master\/simple-cipher\/simple_cipher.go\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<h3 class=\"has-text-align-center wp-block-heading\">&#8212; THE &#8211; END &#8212; <\/h3>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So continuing from the last blog where I wrote a crude version of SimpleCipher and was inclined on removing the duplicate code, here I am with the improved version. Handy links `fmt` package `strings` package. Defining types While I compiled and unit tested code the general feeling was what can be optimized. The obvious choice [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":654,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[68,23,30],"class_list":["post-650","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","tag-cipher","tag-golang","tag-optimisation","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=650"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/650\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/654"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}