Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to calculate the modular multiplicative inverse for the Affine Cipher
    text
    copied!<p>I am trying to create a small software that does the Affine Cipher, which means that <strong>K1</strong> and the amount of letters in the alphabet (using <strong>m</strong> for this number) must be coprime, that is <code>gcd(k1, m) == 1</code>.</p> <p>Basically it's like this:</p> <p>I have a plaintext: <strong>hey</strong></p> <p>I have K1: <strong>7</strong></p> <p>I have K2: <strong>5</strong></p> <p>Plaintext in numerical format is: <strong>8 5 25</strong></p> <p>8 - from h (the position in the alphabet) and ** 5 25** goes the same for <strong>e</strong> and <strong>y</strong></p> <p>Encrypted: <strong>7 13 18</strong></p> <p>Which is the formula:</p> <p><strong>k1 * 8 + k2 mod 27</strong> = 7</p> <p><strong>k1 * 5 + k2 mod 27</strong> = 13</p> <p><strong>k1 * 25 + k2 mod 27</strong> = 18</p> <p>I have a function that crypts this but I don't know how to decrypt.</p> <p>For example I have 7 for h. I want to get the number 8 back again, knowing 7, k1 and k2.</p> <p>Do you guys have any ideas ?</p> <p>Some function where you input k1, k2, result (7 for example, for h), and it gives me back 8, but I really don't know how to reverse this.</p> <p>The function for encryption is this:</p> <pre><code>public List&lt;int&gt; get_crypted_char(string[] strr) { List&lt;int&gt; l = new List&lt;int&gt;(); int i; for (i = 0; i &lt; strr.Length; i++) { int ch = int.Parse(strr[i]); int numberback = k1 * ch + 5; numberback = (numberback % 27); l.Add(numberback); } return l; } </code></pre> <p>Where: string[] strr is a string that contains the plaintext. <strong>Function example:</strong> get_crypted_char({"e","c","b"})</p> <p>The result would be a list like this {"5","3","2"}</p> <p><strong>UPDATE:</strong> Here is a link from wikipedia about this encryption, and also decryption, but ... I don't really understand "how to" <a href="http://en.wikipedia.org/wiki/Affine_cipher" rel="nofollow">http://en.wikipedia.org/wiki/Affine_cipher</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload