1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| import SwiftUI import Foundation
let table = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF" let Chartable = Array(table) let xorinit: UInt64 = 177451812 let addinit: UInt64 = 100618342136696320 let order = [11, 10, 3, 8, 4, 6, 2, 9, 5, 7] let order2 = [6, 2, 4, 8, 5, 9, 3, 7, 1, 0] let magicnumber = UInt64(0x80000000)
func powInt(_ x: UInt64, _ n: Int) -> UInt64 { var powN: UInt64 = 1 for _ in 0..<n { powN *= x } return powN }
func y(_ x: UInt64, _ n: Int) -> UInt64 { var powN: UInt64 = 1 for _ in 0..<n { powN *= 58 } return (x / powN) % 58 }
func conv(input:String)->String { var ansOut="" var isNew=false let inString = input if inString.hasPrefix("a") || inString.hasPrefix("A") { var numIn: UInt64 = 0 let startIndex = inString.index(inString.startIndex, offsetBy: 2) for char in inString[startIndex...] { numIn *= 10 if let digit = char.wholeNumberValue { numIn += UInt64(digit) } } if numIn>1000000000{ isNew=true } numIn = numIn ^ xorinit numIn += addinit if isNew { numIn-=magicnumber } var ansTmp = Array(repeating: UInt64(0), count: 10) for i in 0..<10 { ansTmp[i] = y(numIn, i) } var ansTmp2 = Array(repeating: UInt64(0), count: 10) for i in 0..<10 { ansTmp2[order[i] - 2] = ansTmp[i] } ansOut="BV" for i in ansTmp2 { ansOut+=String(Chartable[Int(i)]) } } else if inString.hasPrefix("b") || inString.hasPrefix("B") { var ansTmp = Array(repeating: UInt64(0), count: 10) for i in 0..<10 { if let j = table.firstIndex(of: inString[inString.index(inString.startIndex, offsetBy: i + 2)]) { ansTmp[i] = UInt64(table.distance(from: table.startIndex, to: j)) } } for i in 0..<10 { ansTmp[i] *= powInt(58, order2[i]) } var ans: UInt64 = 0 for i in ansTmp { ans += i } if ans<addinit { ans+=magicnumber } ans -= addinit ansOut="av\(ans ^ xorinit)" } else { ansOut="Error: Input is neither av nor bv" } return ansOut }
|