~poldi1405/go-yenc

ref: db8820d1a641a361e795ea23f26415f1c5eec62d go-yenc/encdec.go -rw-r--r-- 552 bytes
db8820d1 — Moritz Poldrack started work on encoder 11 months ago
                                                                                
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
package yenc

import "unsafe"

func yenc(input *[8]byte) []byte {
	var mask [8]bool

	// add 42 (0x2a) to every byte
	*(*uint64)(unsafe.Pointer(&input)) += 0x2a2a2a2a2a2a2a2a

	for i := 0; i < 8; i++ {
		bte := (*(*[8]byte)(unsafe.Pointer(&input)))[i]

		if bte == 0x00 || bte == 0x0A || bte == 0x0D || bte == 0x3D {
			(*(*[8]byte)(unsafe.Pointer(&input)))[i] += uint8(64)
			mask[i] = true
		}
	}

	var result []byte
	for i := 0; i < 8; i++ {
		if mask[i] {
			result = append(result, '=')
		}
		result = append(result, input[i])
	}
	return result
}