There is the better way of using the StringBuilder class. Result += (char)((data + offset) % 127) īe advised, that string operations like += will cause the creation of a new string each time so it is not a good example from an (memory)performance point of view. (because it will be a number due to + and %) Add the offset to the current character and just take the If you already have an account: You can use your existing account without paying again to access Typesy. If you don't have an account: Open Typesy and sign up using the activation code provided in the email. Knowing this you can easily build a method like the following one (where I have assumed, that there is no character with a value greater than 127): static string Encrypt(string data, int offset) If you are using a tablet, you must connect a physical keyboard to use Typesy. (text + offset) % NumberOfPossibleCharacters should do the trick. These sitations can be resolved using either if statements or possibly easier by just looking at the rest of the division with the maximum value range. The second one represents the same situation on the upper boundary. There are two special cases you need to consider: What happens if the value you are looking at is on the lower boundary and you substract the offset (meaning, the "new" value would be lower than zero). So it would be much easier building one method that has the ability to do exactly that for a specified text. The installation was a breeze and my friend is making great strides in improving her. The idea behind this type of encryption is, that you take one character and replace it with another one which is offset characters away. Upon making the purchase I received an email with the activation code. Therefore you "just" need to shift every character and this can be done much easier than writing switch- case statements like you did. I guess the next thing you want to do is using Caesar cipher for encrypting/decrypting data. So the Main method would look something like that: public static void Main(string args) ![]() So you could exchange the current if statements with switch (Console.ReadKey(true).Key) and build cases like case ConsoleKey.Y: ![]() By using the overloaded method and specifying true as argument, you won't even see the pressed key on written into the console window ( Console.ReadKey(true)). If the user shall only be able to press y or n, you could use the Console.ReadKey() method instead of letting the user input a complete line of text. Public static char ConvertNumberToLetter(int Number)Īctually there are a few things you could improve. Public static int ConvertLetterToNumber(char Letter) If the shift is smaller or equal to 25, continue to shift one at a time if the user types in "n", write "Goodbye" and close the program if the user types "y", activate the decryption method I've made a program where I can decrypt some encrypted text, it does this by reading a text file and shifting the text one letter at a time, and it does this 26 times, but I can't get it to save and write the output to a text file, this is my code below, I would appreciate any help if possible, thank you using System Ĭonsole.WriteLine("Welcome to the Ceaser Cipher Shift Program") Ĭonsole.WriteLine("Would You Like to Decrypt a File (y for yes/n for no)")
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |