Skip to content

Commit

Permalink
add Decrypt function in c#
Browse files Browse the repository at this point in the history
  • Loading branch information
iarash84 authored Oct 3, 2020
1 parent 15c9895 commit 735ac80
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions c#/CaesarLib/Caesar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,23 @@ static public string Encrypt(string text, int shift)
}
return message;
}

/// <summary>
/// decrypt string using Caesar Cipher
/// </summary>
/// <param name="text">string to decrypt</param>
/// <param name="shift">Shift by how many letters</param>
/// <returns>decrypted string</returns>
static public string Decrypt(string text, int shift)
{
string message = null;
for (int i = 0; i < text.Length; i++)
{
int ASCII = (int)text[i];
message += (char)(ASCII - shift);
}

return message;
}
}
}

0 comments on commit 735ac80

Please sign in to comment.