Skip to content

Commit bdc2f27

Browse files
committed
Minor updates
Fixed a bug I had introduced in NaiveStringSearch.go, cleaned up the unnecessary comments in diffieHellmanKeyExchange.go...
1 parent 8e01f3d commit bdc2f27

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

ciphers/diffieHellmanKeyExchange.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ func main(){
1212
p should ideally be a large prime number but any integer works
1313
g should be a small integer, 2,3 works fine
1414
15-
PS: Note that the secret keys are never send over
16-
the network
15+
PS: Note that the secret keys are never send over the network
1716
*/
1817

1918
p:=2+rand.Intn(1<<bit)
@@ -37,8 +36,7 @@ func main(){
3736
fmt.Printf("Bob sends to Alice: %v\n",BobSends)
3837

3938
//Both parties calculate the shared secret key from the value send
40-
//(value_sent^secret_key)%p
41-
//Both calculations end up with same value despite the different inputs
39+
4240
AliceComputes :=modularExponentiation(BobSends,AliceSecret,p)
4341
BobComputes := modularExponentiation(AliceSends,BobSecret,p)
4442

@@ -50,11 +48,8 @@ func main(){
5048
sharedKey:=AliceComputes
5149
fmt.Println("Voila, shared key is ",sharedKey)
5250
}
53-
54-
55-
56-
5751
}
52+
5853
func modularExponentiation(b int, e int, mod int)int{
5954
//runs in O(log(n)) where n = e
6055
//uses exponentiation by squaring to speed up the process

ciphers/xorCipher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func main(){
3737
temp:= []rune(str)
3838
message:=toASCII(temp)
3939
encrypted:=encrypt(key,message)
40+
//ciphertext:=decodeToString(key,message)
4041
decrypted:=decrypt(key,encrypted)
4142
plaintext:=decodeToString(decrypted)
4243
fmt.Println(plaintext)

sorts/sorts_case_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type sortTest struct {
1313
name string
1414
}
1515

16-
var arr []int = makeRandArray(500_000)
16+
var arr []= makeRandArray(500_000)
1717

1818

1919
var sortTests = []sortTest{

strings/naiveStringSearch.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ import (
1717
func naivePatternSearch(text string, pattern string) []int {
1818
var positions []int
1919
for i := 0; i < len(text)-len(pattern); i++ {
20-
var match bool = true
20+
var match = true
2121
j := i +(len(pattern))
22-
if text[i+j] != pattern[j] {
22+
if text[i:j] != pattern {
2323
match = false
24-
break
25-
}
26-
24+
continue
25+
}
2726
if match {
2827
positions = append(positions, i)
2928
}
@@ -34,11 +33,12 @@ func naivePatternSearch(text string, pattern string) []int {
3433
func main() {
3534
text := "ABAAABCDBBABCDDEBCABC"
3635
pattern := "ABC"
37-
var positions []int = naivePatternSearch(text, pattern)
36+
positions := naivePatternSearch(text, pattern)
3837
if len(positions) == 0 {
39-
fmt.Printf("Pattern not found in given text!")
38+
fmt.Println("Pattern not found in given text!")
4039
} else {
41-
fmt.Printf("Pattern found in following position:\n")
42-
fmt.Printf("%v", positions)
40+
fmt.Println("Pattern found in following position(s):")
41+
fmt.Printf("%v \n", positions)
42+
fmt.Println("Note that position is zero indexed :)")
4343
}
4444
}

0 commit comments

Comments
 (0)