-
Notifications
You must be signed in to change notification settings - Fork 15
/
qrmath.go
59 lines (51 loc) · 1.13 KB
/
qrmath.go
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
package dproject
/**
*
Copyright (c) 2009 Kazuhiko Arase
URL: http://www.d-project.com/
Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php
The word "QR Code" is registered trademark of
DENSO WAVE INCORPORATED
http://www.denso-wave.com/qrcode/faqpatent-e.html
*/
import "log"
// QRMath describes the QRMath structure.
type QRMath struct {
expTable [256]int
logTable [256]int
}
// NewQRMath constructs QRMath object.
func NewQRMath() *QRMath {
qrmath := new(QRMath)
for i := 0; i < 8; i++ {
qrmath.expTable[i] = 1 << i
}
for i := 8; i < 256; i++ {
qrmath.expTable[i] = qrmath.expTable[i-4] ^
qrmath.expTable[i-5] ^
qrmath.expTable[i-6] ^
qrmath.expTable[i-8]
}
for i := 0; i < 255; i++ {
qrmath.logTable[qrmath.expTable[i]] = i
}
return qrmath
}
// Glog returns the log value.
func (qrmath *QRMath) glog(index int) int {
if index < 1 {
log.Fatal("The index value must be between 0 and 255.")
}
return qrmath.logTable[index]
}
// Gexp returns the exp value.
func (qrmath *QRMath) gexp(n int) int {
for n < 0 {
n += 255
}
for n >= 256 {
n -= 255
}
return qrmath.expTable[n]
}