-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaesarCracker.go
43 lines (38 loc) · 1.03 KB
/
caesarCracker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"strings"
"bufio"
"os"
)
const (
firstChar = 1040
lastChar = 1071
)
func main() {
fmt.Print("Type encrypted text: ")
reader := bufio.NewReader(os.Stdin)
s, err := reader.ReadString('\n')
if err != nil {
fmt.Println("Error reading input:", err)
return
}
s = strings.ToUpper(strings.TrimSpace(s))
for shift := 1; shift < 32; shift++ {
fmt.Printf("Сдвиг %d: ", shift)
var result strings.Builder
for _, currentRune := range s {
current := int(currentRune)
if current >= firstChar && current <= lastChar {
shifted := current - shift
if shifted < firstChar {
shifted = lastChar - (firstChar - shifted - 1)
}
result.WriteRune(rune(shifted))
} else {
result.WriteRune(currentRune)
}
}
fmt.Println(result.String())
}
}