GolangNote

Golang笔记

golang rot13 简单加密字符

Permalink

ROT13 是一种简单的字符加密方法,把 26 个英文字母的前 13 个字母与后 13 个字母的编码互换。

Go: rot13 简单加密字符
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
package main

import (
	"io"
	"os"
	"strings"
)

type rot13Reader struct {
	r io.Reader
}

func rot13byte(sb byte) byte {
	s := rune(sb)
	if s >= 'a' && s <= 'm' || s >= 'A' && s <= 'M' {
		sb += 13
	}
	if s >= 'n' && s <= 'z' || s >= 'N' && s <= 'Z' {
		sb -= 13
	}

	return sb
}
func (rot13 rot13Reader) Read(data []byte) (readed int, err error) {
	readed, err = rot13.r.Read(data)
	for i := 0; i < readed; i++ {
		data[i] = rot13byte(data[i])
	}

	return
}

func main() {
	s := strings.NewReader("Lbh penpxrq gur pbqr!")
	r := rot13Reader{s}
	io.Copy(os.Stdout, &r)
}

本文网址: https://golangnote.com/topic/164.html 转摘请注明来源

Related articles

Golang实现简单的Socks5代理

Socks5 代理较 `http/https` 代理有较好的性能,下面是借鉴某个著名开源软件的 local 实现的简单代理。...

Golang phantomjs 动态代理实现

phantomjs 是个很优秀的软件,虽然现在被chrome headless 抢了风头,但在某些特定场合,使用phantomjs 还是很方便,这里是介绍使用Go 实现动态代理。...

Write a Comment to "golang rot13 简单加密字符"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.20 Processed in 0ms