<commit_before>package main

import (
    "fmt"
    "os"
    "crypto/aes"
    "crypto/cipher"
    "io"
)

func Encrypt(in io.Reader, key []byte) io.Reader {

    // Load the plaintext message you want to encrypt.
    plaintext := []byte("hello, world")
    if len(os.Args) > 1 {
        plaintext = []byte(os.Args[1])
    }

    // Setup a key that will encrypt the other text.
    key_text := "<KEY>"
    if len(os.Args) > 2 {
        key_text = os.Args[2]
    }

    // We chose our cipher type here in this case
    // we are using AES.
    c, err := aes.NewCipher([]byte(key_text))
    if err != nil {
        fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key_text), err)
        os.Exit(-1)
    }

    // We use the CFBEncrypter in order to encrypt
    // the whole stream of plaintext using the
    // cipher setup with c and a iv.
    cfb := cipher.NewCFBEncrypter(c, key)
    ciphertext := make([]byte, len(plaintext))
    cfb.XORKeyStream(ciphertext, plaintext)
    fmt.Printf("%s=>%x\n", plaintext, ciphertext)


    var r io.Reader
    return r
}

func Decrypt(in io.Reader, key []byte) io.Reader {

    // Load the plaintext message you want to encrypt.
    plaintext := []byte("hello, world")
    if len(os.Args) > 1 {
    plaintext = []byte(os.Args[1])
    }

    // Setup a key that will encrypt the other text.
    key_text := "<KEY>"
    if len(os.Args) > 2 {
    key_text = os.Args[2]
    }

    // We chose our cipher type here in this case
    // we are using AES.
    c, err := aes.NewCipher([]byte(key_text))
    if err != nil {
    fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key_text), err)
    os.Exit(-1)
    }

    // We decrypt it here just for the purpose of
    // showing the fact that it is decryptable.
    cfbdec := cipher.NewCFBDecrypter(c, commonIV)
    plaintextCopy := make([]byte, len(plaintext))
    cfbdec.XORKeyStream(plaintextCopy, ciphertext)
    fmt.Printf("%x=>%s\n",ciphertext, plaintextCopy)

    var r io.Reader
    return r
}

func main() {
    var a io.Reader
    var commonIV = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}
    Encrypt(a, commonIV)
    Decrypt(a, commonIV)
}<commit_msg>Encryption working, decryption is broken as ****<commit_after>package main

import (
    "fmt"
    "os"
    "crypto/aes"
    "crypto/cipher"
    "io"
    "bytes"
    "strings"
    "crypto/sha256"
)

var commonIV = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}

func Encrypt(in io.Reader, key string) io.Reader {

    // Convert io.Reader to string
    buf := new(bytes.Buffer)
    buf.ReadFrom(in)
    s := buf.String()

    // Load the plaintext message you want to encrypt.
    plaintext := []byte(s)

    // Setup a key that will encrypt the other text.
    h := sha256.New()
    io.WriteString(h, key)
    key_text := h.Sum(nil)

    // We chose our cipher type here in this case we are using AES.
    c, err := aes.NewCipher([]byte(key_text))
    if err != nil {
        fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key_text), err)
        os.Exit(-1)
    }

    // We use the CFBEncrypter in order to encrypt
    // the whole stream of plaintext using the
    // cipher setup with c and a iv.
    cfb := cipher.NewCFBEncrypter(c, commonIV)
    ciphertext := make([]byte, len(plaintext))
    cfb.XORKeyStream(ciphertext, plaintext)
    fmt.Printf("%s=>%x\n", plaintext, ciphertext)

    return strings.NewReader(string(ciphertext))
}

func Decrypt(in io.Reader, key string) io.Reader {

    buf := new(bytes.Buffer)
    buf.ReadFrom(in)
    s := buf.String()
    fmt.Println(s)

    return strings.NewReader(string(plaintext))
}

func main() {
    a := strings.NewReader("hello world yo!")
    Encrypt(a, "password")
    Decrypt(a, "password")
}
{'fraction_non_alphanumeric': 0.14012572027239392, 'fraction_numerical': 0.02645364064955474, 'mean_word_length': 2.6580459770114944, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4969852', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1395, 'n_words': 392}