public static void Main()
Console.Write("Please enter a non-negative integer to encrypt: ");
userInput = Convert.ToInt32(Console.ReadLine());
int encryptedInteger = Encrypt(userInput);
Console.WriteLine("Encrypted Integer: {0:D4}", encryptedInteger);
Console.Write("Please enter a non-negative integer to decrypt: ");
userInput = Convert.ToInt32(Console.ReadLine());
int finalDecryptedInteger = Decrypt(userInput);
Console.WriteLine("Decrypted Integer: {0:D4}", finalDecryptedInteger);
public static int Encrypt(int userInput)
int firstDigit = (userInput / 1000 + 7) % 10;
int secondDigit = (userInput / 100 + 7) % 10;
int thirdDigit = (userInput / 10 + 7) % 10;
int fourthDigit = (userInput / 1 + 7) % 10;
int newFirstDigit = thirdDigit;
int newSecondDigit = fourthDigit;
int newThirdDigit = firstDigit;
int newFourthDigit = secondDigit;
int encryptedInteger = newFirstDigit * 1000 + newSecondDigit * 100 +
newThirdDigit * 10 + newFourthDigit * 1;
public static int Decrypt(int encryptedInput)
int decryptedFirstDigit = (encryptedInput / 1000) % 10;
int decryptedSecondDigit = (encryptedInput / 100) % 10;
int decryptedThirdDigit = (encryptedInput / 10) % 10;
int decryptedFourthDigit = (encryptedInput / 1) % 10;
int newDecryptedFirstDigit = decryptedThirdDigit;
int newDecryptedSecondDigit = decryptedFourthDigit;
int newDecryptedThirdDigit = decryptedFirstDigit;
int newDecryptedFourthDigit = decryptedSecondDigit;
int decryptedUserInput = newDecryptedFirstDigit * 1000 + newDecryptedSecondDigit * 100 +
newDecryptedThirdDigit * 10 + newDecryptedFourthDigit * 1;
int finalDecryptedFirstDigit = (decryptedUserInput / 1000 - 7) % 10;
int finalDecryptedSecondDigit = (decryptedUserInput / 100 - 7) % 10;
int finalDecryptedThirdDigit = (decryptedUserInput / 10 - 7) % 10;
int finalDecryptedFourthDigit = (decryptedUserInput / 1 - 7) % 10;
int finalDecryptedInteger = finalDecryptedFirstDigit * 1000 + finalDecryptedSecondDigit * 100 +
finalDecryptedThirdDigit * 10 + finalDecryptedFourthDigit * 1;
return finalDecryptedInteger;