github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/baidupcs/netdisksign/sign2.go (about) 1 package netdisksign 2 3 func Sign2(j, r []rune) []byte { 4 var ( 5 a = make([]rune, 256) 6 p = make([]rune, 256) 7 o = make([]byte, len(r)) 8 v = len(j) 9 q int 10 u rune 11 i int 12 k rune 13 dr int 14 ) 15 if v == 0 { 16 return o 17 } 18 for ; q < 256; q++ { 19 dr = q % v 20 a[q] = j[dr : 1+dr][0] 21 p[q] = rune(q) 22 } 23 for q = 0; q < 256; q++ { 24 u = (u + p[q] + a[q]) % 256 25 p[q], p[u] = p[u], p[q] 26 } 27 u = 0 28 for q = 0; q < len(r); q++ { 29 i = (i + 1) % 256 30 u = (u + p[i]) % 256 31 p[i], p[u] = p[u], p[i] 32 k = p[(p[i]+p[u])%256] 33 o[q] = byte(r[q] ^ k) 34 } 35 return o 36 }