title: Checksum for SSN
body: <p>I have a project that needs to do validation on the frontend for an American Social Security Number (format <code>ddd-dd-dddd</code>). One suggestion would be to use a hash algorithm, but given the tiny character set used (<code>[0-9]</code>), this would be disastrous. It would be acceptable to validate with some high probability that a number is correct and allow the backend to do a final <code>==</code> check, but I need to do far better than "has nine digits" etc etc. </p>
  
  <p>In my search for better alternatives, I came upon the validation checksums for <a href="https://secure.wikimedia.org/wikipedia/en/wiki/ISBN#ISBN-13" rel="nofollow">ISBN</a> numbers and <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Universal_Product_Code" rel="nofollow">UPC</a>. These look like a great alternative with a high probability of success on the frontend.</p>
  
  <p>Given those constraints, I have three questions:</p>
  
  <ol>
  <li>Is there a way to prove that an algorithm like ISBN13 will work with a different category of data like SSN, or whether it is more or less fit to the purpose from a security perspective? The checksum seems reasonable for my quite large sample of one real SSN, but I'd hate to find out that they aren't generally applicable for some reason.</li>
  <li>Is this a solved problem somewhere, so that I can simply use a pre-existing validation scheme to take care of the problem?</li>
  <li>Are there any such algorithms that would also easily accommodate validating the last 4 digits of an SSN without giving up too much extra information?</li>
  </ol>
  
  <p>Thanks as always,
  Joe</p>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p>In response to a question below, a little more detail. I have the customer's SSN as previously entered, stored securely on the backend of the app. What I need to do is verification (to the maximum extent possible) that the customer has entered that same value again on <em>this</em> page. The issue is that I need to prevent the information from being incidentally revealed to the frontend in case some non-authorized person is able to access the page.</p>
  
  <p>That is why an MD5/SHA1 hash is inappropriate: namely that it can be used to derive the complete SSN without much difficulty. A checksum (say, modulo 11) provides nearly no information to the frontend while still allowing a high degree of accuracy for the field validation. However, as stated above I have concerns over its general applicability.</p>