Swift Playgrounds에서 시저 암호를 만들려고 시도하고 있지만 "W"와 같은 문자가있을 때마다 "A"를 얻는 대신 4로 이동하려고합니다. 오류. 내가 할 이유Swift4 Playgrounds Caesar Cipher 오류
이func cipher(messageToCipher: String, shift: UInt32) {
var ciphredMessage = ""
for char in messageToCipher.unicodeScalars {
var unicode : UInt32 = char.value
if char.value > 64 && char.value < 123 {
var modifiedShift = shift
if char.value >= 65 && char.value <= 90 {
while char.value + modifiedShift > 90 {
//return to A
modifiedShift -= 26
}
} else if char.value >= 97 && char.value <= 122 {
while char.value + modifiedShift > 122 {
//return to a
modifiedShift -= 26
}
}
unicode = char.value + modifiedShift
}
ciphredMessage += String(UnicodeScalar(unicode)!)
}
print(ciphredMessage)
}
사람이 말해 줄 수 : 아스키 코드 + 시프트 Z의 아스키 코드를 초과하지 않는 경우, 그렇지 않으면 내가 여기
내 코드입니다 얻을, 잘 작동 문자 + 시프트의 ASCII 코드가 "z"의 ASCII 코드를 초과하면 오류가 발생합니까?error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
가 0보다 낮은 그렇지 않으면만큼이 조건이 예 – Qbyte
을 성취 그것에서 뺄 수, 나는 삭제 내 내가 인터넷에서 UInt32의 범위를 확인하고 내가 바보라는 것을 깨닫고 나서 의견을 말하십시오. 고마워, UInt32 범위에 대해 잠깐 생각하지 않았다. – AndreiVataselu