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.
for(auto&c:s){/*this is for each loop which get the every character in 's' to c where c is auto datatype*/}if(isalpha(c)){/* this if block allows only alphabetic characters which should be encrypted*/}a=isupper(c)?65:97{/*according to current character's case, using tunary operator the case of letter 'A' is assinged.*/}c=a+(c-a+rot)%26{{/*the encryption part. here the current character(c) is rotated to the given rot value i.e c+rot */}{/*{then to the get the exact rotation it pulls down the character using the letter('A')'s case i.e c+rot-a */}{/*now to get the new character in the alphabetic rage it use modulo of 26(i.e we have 26 alphabet)*/}{/*then to get that character in the Ascii alphabetic range he add letter('A')'s case to it. (i.e a+(c-a+rot)%26)*/}}
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 →