Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4. import "math"
  5. import "strconv"
  6. import "os"
  7.  
  8. func init() {
  9. if len(os.Args) != 3 {
  10. fmt.Fprintln(os.Stderr, "wrong number of args")
  11. os.Exit(1)
  12. }
  13. mathId = os.Args[1]
  14. activationKey = os.Args[2]
  15. }
  16.  
  17. // var mathId = document.getElementById("str").value;
  18. var mathId string
  19.  
  20. // var activationKey = document.getElementById("act").value;
  21. var activationKey string
  22.  
  23. func f1(n int, b byte, c int) int {
  24. for bitIndex := 0; bitIndex <= 7; bitIndex++ {
  25. bit := (b >> uint8(bitIndex)) & 1
  26. if int(bit)+((n-int(bit)) & ^1) == n {
  27. n = (n - int(bit)) >> 1
  28. } else {
  29. n = ((c - int(bit)) ^ n) >> 1
  30. }
  31. }
  32. return n
  33. }
  34.  
  35. // str is fmt.Sprintf("%s$1&%s", mathId, activationKey)
  36. func genPassword(mathId, activationKey string) string {
  37. str := fmt.Sprintf("%s$1&%s", mathId, activationKey)
  38. hash := 0xA439
  39. for byteIndex := len(str) - 1; byteIndex >= 0; byteIndex -= 1 {
  40. hash = f1(hash, byte(str[byteIndex]), 0x105C3)
  41. }
  42. n1 := 0
  43. for f1(f1(hash, byte(n1&0xFF), 0x105C3), byte(n1>>8), 0x105C3) != 0xA5B6 {
  44. n1 += 1
  45. if n1 >= 0xFFFF {
  46. panic(fmt.Errorf("Error"))
  47. }
  48. }
  49. n1 = int(math.Floor(float64((n1+0x72FA)&0xFFFF) * 99999.0 / 0xFFFF))
  50. n1str := fmt.Sprintf("0000%d", n1)
  51. n1str = n1str[len(n1str)-5:]
  52. temp, _ := strconv.Atoi(n1str[0:2] + n1str[3:] + n1str[2:3]) // 12 + 45 + 3
  53. temp = int(math.Ceil((float64(temp) / 99999.0) * 0xFFFF))
  54. temp = f1(f1(0, byte(temp&0xFF), 0x1064B), byte(temp>>8), 0x1064B)
  55. for byteIndex := len(str) - 1; byteIndex >= 0; byteIndex-- {
  56. temp = f1(temp, byte(str[byteIndex]), 0x1064B)
  57. }
  58.  
  59. n2 := 0
  60. for f1(f1(temp, byte(n2&0xFF), 0x1064B), byte(n2>>8), 0x1064B) != 0xA5B6 {
  61. n2 += 1
  62. if n2 >= 0xFFFF {
  63. panic(fmt.Errorf("Error"))
  64. }
  65. }
  66. n2 = int(math.Floor(float64(n2&0xFFFF) * 99999.0 / 0xFFFF))
  67. n2str := fmt.Sprintf("0000%d", n2)
  68. n2str = n2str[len(n2str)-5:]
  69.  
  70. return n2str[3:4] +
  71. n1str[3:4] +
  72. n1str[1:2] +
  73. n1str[0:1] +
  74. "-" +
  75. n2str[4:5] +
  76. n1str[2:3] +
  77. n2str[0:1] +
  78. "-" +
  79. n2str[2:3] +
  80. n1str[4:5] +
  81. n2str[1:2] +
  82. "::1"
  83. }
  84.  
  85. func main() {
  86. fmt.Println(genPassword(mathId, activationKey))
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement