WALTER | Workable Algorithms for Location-aware Transmission, Encryption Response

StringExtensions..::..AsNumeric Method

Decodes a numeric encoded string, originally representing a password or sensitive information, back to its textual form. This method reverses the encoding applied by AsNumeric, allowing secure retrieval of the original string from its bigint numeric representation.

Namespace:  System.Text
Assembly:  Walter.Cypher (in Walter.Cypher.dll)

Syntax


[CodeSampleAttribute]
public static string AsNumeric(
	this string value
)

Parameters

value
Type: String
The bigint numeric encoded string to be decoded.

Return Value

The original text, typically a password, encoded in the numeric string.

Remarks


This decoding process is tailored for numeric encoded strings created by AsNumeric, offering an effective means of retrieving sensitive information stored in an unconventional numeric format. The approach ensures that even if attackers recognize the bigint value as a password, reversing the encoding without the specific decoding logic remains impractical. It's crucial to decode the value only in secure environments to maintain the integrity of the original information.

Examples


Here is a unit test that shows and allows you to validate the security and functional aspects of the encoding/decoding process, allowing you to ensure the method is effective against the most common attack vectors.

The test bellow would generate the following TestContext Messages:

Test1: The Numeric values of the same phrase should result in different values.
The Numeric value of Pa$$word is:766580654759767643676203645868119877711146611148768100 and 6568880678397674436665436852321194736111875911485904100. Equal:False


Test 2:
Expect:''Pa$$word''
Actual:''Pa$$word''
Equal:True

Test 3:
Expect:''Pa$$word''
Actual:''Pa$$word''
Equal:True

Enhanced security of the system by providing variable responses or demonstrating non-deterministic output.
[TestMethod()]
   public void IsRandomTest()
   {
       var secretString = "Pa$word";
       var encrypted1 = secretString.AsNumeric();
       var encrypted2 = secretString.AsNumeric();

       _context.WriteLine($"Test1: The Numeric values of the same phrase should result in different values.\nThe Numeric value of {secretString} is:{encrypted1} and {encrypted2}. Equal:{encrypted1.Equals(encrypted2, StringComparison.InvariantCultureIgnoreCase)}\n\n");
       Assert.AreNotEqual(encrypted1,encrypted2);
       int loopNr = 1;
       foreach (var decrypted in new string[] { encrypted1.FromNumeric(), encrypted2.FromNumeric() })
       {

           _context.WriteLine($"Test {++loopNr}:\nExpect:''{secretString}''\nActual:''{decrypted}''\nEqual:{secretString.Equals(decrypted,StringComparison.Ordinal)}\n");
           Assert.AreEqual(secretString, decrypted);
       }
   }