fun 凯撒加密测试(){ var str:String = "有了具名参数,有默认值的参数就没必要放在右边了;swift的外部参数,同 样解决了了这本问题" var result0 = ecrypt(str, 1) println(result0) println(decrypt(input = result0, key = 1)) } fun ecrypt(input:String, key:Int): String { var charArray = input.toCharArray() return with(StringBuffer()){ charArray.forEach { var asc = it.toInt() asc += key var result = asc.toChar() append(result) } toString() } } fun decrypt(input:String, key:Int):String{ var charArray = input.toCharArray() return with(StringBuffer()){ charArray.forEach { var asc = it.toInt() asc -= key var result = asc.toChar() append(result) } toString() } }
02-02
12-05
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)