Skip to content

Instantly share code, notes, and snippets.

Avatar

melkael

View GitHub Profile
View challenge08.go
func countDuplicates(elem [10][]byte) int {
tmp := elem
ret := 0
for i := range tmp {
for j := range elem {
if i != j && reflect.DeepEqual(tmp[i], elem[j]) {
ret++
}
}
}
View challenge07.go
func ReadFile(filename string) []byte {
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
scan := bufio.NewScanner(file)
bytes := make([]byte, 0, 1024)
for scan.Scan() {
input := []byte(scan.Text())
View suite challenge06.go
func distanceBetweenChunks(keysize int, data string) float64 {
// we are using hex string here as input : one ascii char is two hex digits long
out := 0.0
totalNumberOfChunks := 0.0
for i := 0; i < len(data)/(5*keysize); i++ {
offset := i * 4 * keysize
firstChunk := data[offset : offset+keysize*2]
secondChunk := data[offset+keysize*2 : offset+4*keysize]
res := float64(hamming(firstChunk, secondChunk))
res /= float64(keysize)
View hamming.go
func hexToBinary(hexnum string) string {
if hexnum == "0" {
return "0000"
} else if hexnum == "1" {
return "0001"
} else if hexnum == "2" {
return "0010"
} else if hexnum == "3" {
return "0011"
} else if hexnum == "4" {
View challenge5.go
func repeatingXorMakeKey(key string, length int) string {
ret := strings.Repeat(key, length/len(key)+1)
return ret[0:length]
}
func repeatingKeyXor(clear string, key string) string {
entryTab := strings.Split(clear, "\n")
output := ""
for i := 0; i < len(entryTab); i++ {
repeatedKey := repeatingXorMakeKey(key, len(entryTab[i]))
View challenge4.go
func decodeMultipleStrings() string {
f, _ := os.Open("4.txt")
fs := bufio.NewScanner(f)
for fs.Scan() {
txt := fs.Text()
decodedString := decoder(txt)
if decodedString != "" {
return decodedString
}
}
View challenge3.go
func decoder(str string) string {
key := ""
best := ""
var max float32 = 0
for i := 0x00; i < 0xFF; i++ {
key = fmt.Sprintf("%c", i)
decodedHex := xorStrToChar(str, key)
decodedAscii := hexToAscii(decodedHex)
if max < rateString(decodedAscii) {
max = rateString(decodedAscii)
View challenge2.go
package main
import "fmt"
import hex "encoding/hex"
func xor_equal_len(hex_s1 string, hex_s2 string) string {
bytes_s1, _ := hex.DecodeString(hex_s1)
bytes_s2, _ := hex.DecodeString(hex_s2)
bytes_xor := make([]byte, len(bytes_s1))
View challenge1.go
package main
import "fmt"
import b64 "encoding/base64"
import hex "encoding/hex"
func hex_to_base64(hex_s string) string {
bytes, _ := hex.DecodeString(hex_s)
sEnc := b64.StdEncoding.EncodeToString(bytes)
View mail.py
def sendEmail(message):
msg = MIMEMultipart()
password = PASS
msg['From'] = EMAIL
msg['To'] = EMAIL
msg['Subject'] = "Log clavier"
msg.attach(MIMEText(message, 'plain'))
You can’t perform that action at this time.