├── LICENSE ├── README.md ├── go.mod ├── go.sum └── pxutils.go /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 iNcizzle 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Perimeterx Helper Functions 2 | 3 | ## Install 4 | ```bash 5 | $ go get github.com/incizzle/perimeterx-utils-go 6 | ``` 7 | ```go 8 | import pxutils "github.com/incizzle/perimeterx-utils-go" 9 | ``` 10 | 11 | ## Usage 12 | 13 | Create PC Variable 14 | ```go 15 | pxutils.CreatePC(jsonstring, tag) // Create PC Variable pass in jsonstring payload and uuid:tag:ftag 16 | ``` 17 | 18 | Obfuscate String 19 | ```go 20 | pxutils.ObfuscateString(text, factor) // Simple Function to Obfuscate string using a factor 21 | ``` 22 | 23 | SimpleTextEncode String 24 | ```go 25 | pxutils.SimpleTextEncode(text, factor) // Simple Function to encode text using a factor 26 | ``` 27 | 28 | DecodePayload String 29 | ```go 30 | pxutils.DecodePayload(text, factor) // DecodePayload decodes a payload using a factor 31 | ``` 32 | 33 | EncodePayload String 34 | ```go 35 | pxutils.EncodePayload(text, factor) // EncodePayload encodes a string using a factor 36 | ``` 37 | 38 | Other Encrpyt Functions 39 | ```go 40 | pxutils.H1(n, t) 41 | ``` 42 | 43 | ```go 44 | pxutils.H12(t) 45 | ``` 46 | 47 | By: iNcizzle#1337 48 | Twitter: https://twitter.com/iNcizzle 49 | Decoder Website: https://px.incizzle.dev/ 50 | Enjoy 💜 -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/incizzle/perimeterx-utils-go 2 | 3 | go 1.15 4 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/incizzle/perimeterx-utils-go/ad39f0fdfa9a163f9ca136e1ac1be3d230b543ae/go.sum -------------------------------------------------------------------------------- /pxutils.go: -------------------------------------------------------------------------------- 1 | package pxutils 2 | 3 | import ( 4 | "encoding/base64" 5 | "strconv" 6 | ) 7 | 8 | // CreatePC Variable pass in jsonstring payload and uuid:tag:ftag 9 | func CreatePC(jsonstring string, tag string) string { 10 | var a = H1(jsonstring, tag) 11 | var e = H12(a) 12 | var r = h13(e) 13 | var pc = "" 14 | 15 | for i := 0; i < len(r); i += 2 { 16 | pc += string(r[i]) 17 | } 18 | return pc 19 | } 20 | 21 | func H1(n string, t string) string { 22 | var e int 23 | r := h2(t) 24 | o := make([]int, 16) 25 | i := make([]int, 16) 26 | if len(r) > 16 { 27 | r = h3(r, 8*len(t)) 28 | } 29 | for e = 0; e < 16; e++ { 30 | if e >= len(r) { 31 | o[e] = 909522486 32 | i[e] = 1549556828 33 | } else { 34 | o[e] = 909522486 ^ r[e] 35 | i[e] = 1549556828 ^ r[e] 36 | } 37 | } 38 | a := h3(append(o, h2(n)...), 512+8*len(n)) 39 | x := h3(append(i, a...), 640) 40 | return h11(x) 41 | } 42 | 43 | func h2(t string) []int { 44 | e := make([]int, (len(t)*8)>>5+1) 45 | for n := 0; n < 8*len(t); n += 8 { 46 | charCode := int([]rune(t)[n/8]) 47 | e[n>>5] |= charCode << (n % 32) 48 | } 49 | return e 50 | } 51 | 52 | func h3(t []int, n int) []int { 53 | var x int32 = 128 << (n % 32) 54 | for i := len(t); i < ((n >> 5) + 1); i++ { 55 | t = append(t, 0) 56 | } 57 | t[n>>5] |= int(x) 58 | var y = 14 + ((n + 64) >> 9 << 4) 59 | for i := len(t); i < y+2; i++ { 60 | t = append(t, 0) 61 | } 62 | t[y] = n 63 | var e int 64 | var r = 0 65 | var o = 0 66 | var i = 0 67 | var a = 0 68 | var c = 1732584193 69 | var u = -271733879 70 | var f = -1732584194 71 | var s = 271733878 72 | for e = 0; e < len(t); e += 16 { 73 | r = c 74 | o = u 75 | i = f 76 | a = s 77 | c = h4(c, u, f, s, t[e], 7, -680876936) 78 | s = h4(s, c, u, f, t[e+1], 12, -389564586) 79 | f = h4(f, s, c, u, t[e+2], 17, 606105819) 80 | u = h4(u, f, s, c, t[e+3], 22, -1044525330) 81 | c = h4(c, u, f, s, t[e+4], 7, -176418897) 82 | s = h4(s, c, u, f, t[e+5], 12, 1200080426) 83 | f = h4(f, s, c, u, t[e+6], 17, -1473231341) 84 | u = h4(u, f, s, c, t[e+7], 22, -45705983) 85 | c = h4(c, u, f, s, t[e+8], 7, 1770035416) 86 | s = h4(s, c, u, f, t[e+9], 12, -1958414417) 87 | f = h4(f, s, c, u, t[e+10], 17, -42063) 88 | u = h4(u, f, s, c, t[e+11], 22, -1990404162) 89 | c = h4(c, u, f, s, t[e+12], 7, 1804603682) 90 | s = h4(s, c, u, f, t[e+13], 12, -40341101) 91 | f = h4(f, s, c, u, t[e+14], 17, -1502002290) 92 | u = h4(u, f, s, c, t[e+15], 22, 1236535329) 93 | c = h5(c, u, f, s, t[e+1], 5, -165796510) 94 | s = h5(s, c, u, f, t[e+6], 9, -1069501632) 95 | f = h5(f, s, c, u, t[e+11], 14, 643717713) 96 | u = h5(u, f, s, c, t[e], 20, -373897302) 97 | c = h5(c, u, f, s, t[e+5], 5, -701558691) 98 | s = h5(s, c, u, f, t[e+10], 9, 38016083) 99 | f = h5(f, s, c, u, t[e+15], 14, -660478335) 100 | u = h5(u, f, s, c, t[e+4], 20, -405537848) 101 | c = h5(c, u, f, s, t[e+9], 5, 568446438) 102 | s = h5(s, c, u, f, t[e+14], 9, -1019803690) 103 | f = h5(f, s, c, u, t[e+3], 14, -187363961) 104 | u = h5(u, f, s, c, t[e+8], 20, 1163531501) 105 | c = h5(c, u, f, s, t[e+13], 5, -1444681467) 106 | s = h5(s, c, u, f, t[e+2], 9, -51403784) 107 | f = h5(f, s, c, u, t[e+7], 14, 1735328473) 108 | u = h5(u, f, s, c, t[e+12], 20, -1926607734) 109 | c = h6(c, u, f, s, t[e+5], 4, -378558) 110 | s = h6(s, c, u, f, t[e+8], 11, -2022574463) 111 | f = h6(f, s, c, u, t[e+11], 16, 1839030562) 112 | u = h6(u, f, s, c, t[e+14], 23, -35309556) 113 | c = h6(c, u, f, s, t[e+1], 4, -1530992060) 114 | s = h6(s, c, u, f, t[e+4], 11, 1272893353) 115 | f = h6(f, s, c, u, t[e+7], 16, -155497632) 116 | u = h6(u, f, s, c, t[e+10], 23, -1094730640) 117 | c = h6(c, u, f, s, t[e+13], 4, 681279174) 118 | s = h6(s, c, u, f, t[e], 11, -358537222) 119 | f = h6(f, s, c, u, t[e+3], 16, -722521979) 120 | u = h6(u, f, s, c, t[e+6], 23, 76029189) 121 | c = h6(c, u, f, s, t[e+9], 4, -640364487) 122 | s = h6(s, c, u, f, t[e+12], 11, -421815835) 123 | f = h6(f, s, c, u, t[e+15], 16, 530742520) 124 | u = h6(u, f, s, c, t[e+2], 23, -995338651) 125 | c = h7(c, u, f, s, t[e], 6, -198630844) 126 | s = h7(s, c, u, f, t[e+7], 10, 1126891415) 127 | f = h7(f, s, c, u, t[e+14], 15, -1416354905) 128 | u = h7(u, f, s, c, t[e+5], 21, -57434055) 129 | c = h7(c, u, f, s, t[e+12], 6, 1700485571) 130 | s = h7(s, c, u, f, t[e+3], 10, -1894986606) 131 | f = h7(f, s, c, u, t[e+10], 15, -1051523) 132 | u = h7(u, f, s, c, t[e+1], 21, -2054922799) 133 | c = h7(c, u, f, s, t[e+8], 6, 1873313359) 134 | s = h7(s, c, u, f, t[e+15], 10, -30611744) 135 | f = h7(f, s, c, u, t[e+6], 15, -1560198380) 136 | u = h7(u, f, s, c, t[e+13], 21, 1309151649) 137 | c = h7(c, u, f, s, t[e+4], 6, -145523070) 138 | s = h7(s, c, u, f, t[e+11], 10, -1120210379) 139 | f = h7(f, s, c, u, t[e+2], 15, 718787259) 140 | u = h7(u, f, s, c, t[e+9], 21, -343485551) 141 | c = h9(c, r) 142 | u = h9(u, o) 143 | f = h9(f, i) 144 | s = h9(s, a) 145 | } 146 | return []int{c, u, f, s} 147 | } 148 | 149 | func h4(t int, n int, e int, r int, o int, i int, a int) int { 150 | return h8(n&e|^n&r, t, n, o, i, a) 151 | } 152 | 153 | func h5(t int, n int, e int, r int, o int, i int, a int) int { 154 | return h8(n&r | e & ^r, t, n, o, i, a) 155 | } 156 | 157 | func h6(t int, n int, e int, r int, o int, i int, a int) int { 158 | return h8(n^e^r, t, n, o, i, a) 159 | } 160 | 161 | func h7(t int, n int, e int, r int, o int, i int, a int) int { 162 | return h8(e^(n|^r), t, n, o, i, a) 163 | } 164 | 165 | func h8(t int, n int, e int, r int, o int, i int) int { 166 | return h9(h10(h9(h9(n, t), h9(r, i)), o), e) 167 | } 168 | 169 | func h9(t int, n int) int { 170 | var e = (65535 & t) + (65535 & n) 171 | return int(int32((int(int32(t>>16))+int(int32(n>>16))+int(int32(e>>16)))<<16)) | 65535&e 172 | } 173 | 174 | func h10(t int, n int) int { 175 | return int(int32(t<> (32 - n))) 176 | } 177 | 178 | func h11(t []int) string { 179 | var n int 180 | var e = "" 181 | for n = 0; n < 32*len(t); n += 8 { 182 | e += string(rune(int(int32(int(uint32(t[n>>5]))>>(n%32)))) & 255) 183 | } 184 | return e 185 | } 186 | 187 | func H12(t string) string { 188 | var n = "0123456789abcdef" 189 | var e = "" 190 | var r = 0 191 | var o int 192 | for o = 0; o < 16; o++ { 193 | r = int([]rune(t)[o]) 194 | e += string(n[int(uint32(r)>>4)&15]) + string(n[15&r]) 195 | } 196 | return e 197 | } 198 | 199 | func h13(t string) string { 200 | var n string = "" 201 | var e string = "" 202 | var r int 203 | for r = 0; r < len(t); r++ { 204 | var o = int([]rune(t)[r]) 205 | if o >= 48 && o <= 57 { 206 | n += string(t[r]) 207 | } else { 208 | e += strconv.Itoa(o % 10) 209 | } 210 | } 211 | return n + e 212 | } 213 | 214 | // ObfuscateString obfuscates a string using a factor 215 | func ObfuscateString(text string, amount int) string { 216 | var e string = "" 217 | for r := 0; r < len(text); r++ { 218 | e += string(rune(amount ^ int([]rune(text)[r]))) 219 | } 220 | return e 221 | } 222 | 223 | // SimpleEncode Simple Function to encode text using a factor 224 | func SimpleTextEncode(text string, factor int) string { 225 | var e string = "" 226 | for r := 0; r < len(text); r++ { 227 | e += fromCharCode(charCodeAt(text, r) ^ factor) 228 | } 229 | 230 | return e 231 | } 232 | 233 | // EncodePayload encodes a string using a factor 234 | func EncodePayload(json string, factor int) string { 235 | var e string = "" 236 | for i := 0; i < len(json); i++ { 237 | e += fromCharCode(charCodeAt(json, i) ^ factor) 238 | } 239 | return base64.StdEncoding.EncodeToString([]byte((e))) 240 | } 241 | 242 | // DecodePayload decodes a payload using a factor 243 | func DecodePayload(payload string, factor int) string { 244 | bytes, _ := base64.StdEncoding.DecodeString(payload) 245 | payload = string(bytes) 246 | var d string = "" 247 | for i := 0; i < len(payload); i++ { 248 | d += fromCharCode(charCodeAt(payload, i) ^ factor) 249 | } 250 | return d 251 | } 252 | 253 | // CharCodeAt https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt 254 | func charCodeAt(str string, n int) int { 255 | if len(str) == 0 || len(str) < n { 256 | return 0 257 | } 258 | 259 | return int([]rune(str)[n]) 260 | } 261 | 262 | // FromCharCode https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/FromCharCode 263 | func fromCharCode(c int) string { 264 | return string(rune(c)) 265 | } 266 | --------------------------------------------------------------------------------