language: Go (gc-2010-07-14)
date: 200 days 10 hours ago
link:
visibility: public
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
 
import (
        "fmt"
        "crypto/aes"
        "time"
        "rand"
)
 
type Key128 [128]byte
type Key256 [256]byte
 
func padPhrase(k *Key128, b []byte) []byte {
        padded := make([]byte, len(k))
        copy(padded, b)
 
        if len(padded) == len(k) {
                fmt.Println("\nKey successfully padded.")
                return padded
        }
        
        fmt.Println("Something happened!")
        return nil
}
 
func main() {
        phrase := "Hi my name is Sheridan."
        key := new(Key128)
        fmt.Println("Created key of length", len(key))
        fmt.Println("Seeding randomization...")
        fmt.Println("NOTICE: This randomization is not top-notch security as it must run in a sandbox.")
        rand.Seed(time.Nanoseconds())
        fmt.Println("Randomization seeded.")
        fmt.Println("Generating", len(key), "random bytes for key.")
        for i := 0; i < len(key); i++ {
                key[i] = byte(rand.Int()%255)
        }
        fmt.Println("\nKey created.")
        fmt.Printf(">> ")
        for b := 0; b < len(key); b++ {
                fmt.Printf("%x", key[b])
        }
        fmt.Printf("\n\n")
        fmt.Println("Phrase to encrypt:", phrase)
        bphrase := make([]byte, len(phrase))
        for b := 0; b < len(bphrase); b++ {
                bphrase[b] = byte(phrase[b])
        }
        fmt.Println("Phrase bytes:", bphrase)
        fmt.Println("Phrase length:", len(bphrase))
        if len(bphrase) < len(key) {
                fmt.Println("Phrase needs to be padded to fit key length.")
                bphrase = padPhrase(key, bphrase)
        } else {
                fmt.Println("Coincidentally, the phrase is just the right size for the key.")
        }
        fmt.Println("Length of new bphrase:", len(bphrase))
        fmt.Println("Bphrase:", bphrase)
        
        cipher, err := aes.NewCipher(key)
        if err != nil {
                fmt.Println("Error in NewCipher():", err)
        }
        
        ephrase := make([]byte, len(bphrase))
        if len(key) == 128 {
                cipher.Encrypt(bphrase[0:16], ephrase[0:16])
                cipher.Encrypt(bphrase[16:32], ephrase[16:32])
                cipher.Encrypt(bphrase[32:64], ephrase[32:64])
                cipher.Encrypt(bphrase[64:96], ephrase[64:96])
                cipher.Encrypt(bphrase[96:128], ephrase[96:128])
        }
        fmt.Println("Bphrase encrypted in 128bit AES!")
        fmt.Println("Ephrase:", ephrase)
        
        fmt.Println("\n\nThis will be a 128-bit and 256-bit AES encryption algorithm when I'm done.")
}
 
  • upload with new input
  • result: Success     time: 0s    memory: 2520 kB     returned value: 2

    Created key of length 128
    Seeding randomization...
    NOTICE: This randomization is not top-notch security as it must run in a sandbox.
    Randomization seeded.
    Generating 128 random bytes for key.
    
    Key created.
    >> 6d4db87ac196cb73b82ce781dec983dc1d1097b3aedf38533a218e9c70634382f1ab9df3d7bd520434225798fb94edac94e713a9d2bc88ba57f32b42b7712a1f0cf9e457f27b32baf4edc40a7c19a1a4489d5fc55e65f5adc3579eaf55874ad4b71aedbccb3c7642f77db1911552e5841536462f6cb0f4c04b74e8c3
    
    Phrase to encrypt: Hi my name is Sheridan.
    Phrase bytes: [72 105 32 109 121 32 110 97 109 101 32 105 115 32 83 104 101 114 105 100 97 110 46]
    Phrase length: 23
    Phrase needs to be padded to fit key length.
    
    Key successfully padded.
    Length of new bphrase: 128
    Bphrase: [72 105 32 109 121 32 110 97 109 101 32 105 115 32 83 104 101 114 105 100 97 110 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    Error in NewCipher(): crypto/aes: invalid key size 128
    
    panic: runtime error: invalid memory address or nil pointer dereference
    
    panic PC=0xb7756a5c
    runtime.panic+0x97 /usr/local/devel/pakiety/go/src/src/pkg/runtime/proc.c:1012
    	runtime.panic(0x0, 0x80980a4)
    panicstring+0x5e /usr/local/devel/pakiety/go/src/src/pkg/runtime/runtime.c:83
    	panicstring(0x80980a4, 0xb776d1c8)
    sigpanic+0x8f /usr/local/devel/pakiety/go/src/src/pkg/runtime/linux/thread.c:285
    	sigpanic()
    crypto/aes.*Cipher·Encrypt+0x22 /usr/local/devel/pakiety/go/src/src/pkg/crypto/aes/cipher.go:56
    	crypto/aes.*Cipher·Encrypt(0x8057a39, 0xb776a3e0, 0xb776a0a0, 0x9, 0x804a524, ...)
    main.main+0xd94 /home/QvJBYB/prog.go:67
    	main.main()
    mainstart+0xf /usr/local/devel/pakiety/go/src/src/pkg/runtime/386/asm.s:83
    	mainstart()
    goexit /usr/local/devel/pakiety/go/src/src/pkg/runtime/proc.c:145
    	goexit()