We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticstringcaesarCipher(strings,intk){// Check if it's shiftabledecimalparsed;if(String.IsNullOrEmpty(s)||decimal.TryParse(s,outparsed))returns;// Remove extra shiftsk=k%26;stringnewString="";foreach(charcins){// Check if character is a letterif(char.IsLetter(c)){// ShiftintnewC=c+k;// Check if char is lower case if(char.IsLower(c)&&newC>'z'){// loop if necessarynewC='a'+(newC-'z'-1);}// Check if char is upper chaseif(char.IsUpper(c)&&newC>'Z'){// loop if necessarynewC='A'+(newC-'Z'-1);}// Add to return string;newString+=(char)newC;}elsenewString+=c;// Add non-char to return string}// return shifted stringreturnnewString;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Caesar Cipher
You are viewing a single comment's thread. Return to all comments →
In C#