Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. mrand "math/rand"
  6. "crypto/aes"
  7. "crypto/cipher"
  8. "encoding/base64"
  9. "errors"
  10. "strings"
  11. )
  12. func addBase64Padding(value string) string {
  13. m := len(value) % 4
  14. if m != 0 {
  15. value += strings.Repeat("=", 4-m)
  16. }
  17.  
  18. return value
  19. }
  20.  
  21. func removeBase64Padding(value string) string {
  22. return strings.Replace(value, "=", "", -1)
  23. }
  24.  
  25.  
  26. func decryptt(key []byte, text string) (string, error) {
  27. block, err := aes.NewCipher(key)
  28. if err != nil {
  29. return "", err
  30. }
  31.  
  32. decodedMsg, err := base64.URLEncoding.DecodeString(addBase64Padding(text))
  33. if err != nil {
  34. return "", err
  35. }
  36.  
  37. if (len(decodedMsg) % aes.BlockSize) != 0 {
  38. return "", errors.New("blocksize must be multipe of decoded message length")
  39. }
  40.  
  41. iv := decodedMsg[:aes.BlockSize]
  42. msg := decodedMsg[aes.BlockSize:]
  43.  
  44. cfb := cipher.NewCFBDecrypter(block, iv)
  45. cfb.XORKeyStream(msg, msg)
  46.  
  47. return string(msg), nil
  48. }
  49.  
  50.  
  51. func main() {
  52. crry := "r_HWVfHUJyYRXjAstd1akDD_svGvtJzLUGE0iEE9jmMWN39i_WJNe0hVbwmpdM4v"
  53. c := 32
  54. mrand.Seed(1337000900080091)
  55. b := make([]byte, c, c)
  56. mrand.Read(b)
  57. msg, _ := decryptt(b, crry)
  58. fmt.Println(msg)
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement