(str string, timeNow int64)
| 261 | } |
| 262 | |
| 263 | func EncodeTimeFlowString(str string, timeNow int64) string { |
| 264 | timeNow = timeNow / 1000 |
| 265 | timeDigits := []int{} |
| 266 | timeDigitIndex := 0 |
| 267 | |
| 268 | if len(str) == 0 { |
| 269 | return "" |
| 270 | } |
| 271 | |
| 272 | str = fmt.Sprintf("%d|%s", timeNow, str) |
| 273 | |
| 274 | res := make([]int32, 0, utf8.RuneCountInString(str)) |
| 275 | for timeNow > 0 { |
| 276 | timeDigits = append(timeDigits, int(timeNow%int64(10))) |
| 277 | timeNow = timeNow / 10 |
| 278 | } |
| 279 | |
| 280 | add := false |
| 281 | for pos, rune := range str { |
| 282 | // take single digit with index timeDigitIndex from timeNow |
| 283 | newIndex := pos |
| 284 | if add { |
| 285 | newIndex = pos + timeDigits[timeDigitIndex]*timeDigitIndex |
| 286 | } else { |
| 287 | newIndex = 2*timeDigitIndex*timeDigits[timeDigitIndex] - pos |
| 288 | } |
| 289 | |
| 290 | if newIndex < 0 { |
| 291 | newIndex = newIndex * -1 |
| 292 | } |
| 293 | |
| 294 | res = append(res, rune) |
| 295 | newIndex = newIndex % len(res) |
| 296 | |
| 297 | res[newIndex], res[len(res)-1] = res[len(res)-1], res[newIndex] |
| 298 | |
| 299 | add = !add |
| 300 | // Add timeDigitIndex by 1, but does not exceed total digits in timeNow |
| 301 | timeDigitIndex++ |
| 302 | timeDigitIndex = timeDigitIndex % len(timeDigits) |
| 303 | } |
| 304 | |
| 305 | return string(res) |
| 306 | } |
| 307 | |
| 308 | func DecodeTimeFlowStringTime(str string, timeNow int64) string { |
| 309 | timeNow = timeNow / 1000 |
nothing calls this directly
no outgoing calls
no test coverage detected