Click here to Skip to main content
15,896,606 members

reverse engineering of code

Emejulu JVT asked:

Open original thread
I'm writting a program to give a user a unique password based on his email address and i found this piece of code online. I'm now trying to reverse the code so that i can get back the email address from the password, pls can anyone tell me start with the decoding.


C#
static char [] ValidChars = { '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'J' , 'K' , 'L' , 'M' , 'N' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' }; // len=32 
const string  hashkey = "password" ; 
//key for HMAC function -- change! 
const int  codelength  = 6 ; // lenth of passcode 
string GetCodeForEmail ( string  address ) 
{ 
byte []  hash ;  
   using  ( HMACSHA1 sha1  = new  HMACSHA1 ( ASCIIEncoding . ASCII .GetBytes ( hashkey )))         hash  =  sha1 . ComputeHash ( UTF8Encoding . UTF8 . GetBytes ( address )); int  startpos  =  hash [ hash . Length - 1 ] % ( hash . Length -  codelength ); StringBuilder  passbuilder  = new StringBuilder (); for ( int  i  =  startpos ;  i  <  startpos  +  codelength ;  i ++)         passbuilder . Append ( ValidChars [ hash [ i ] % ValidChars . Length ]); return  passbuilder . ToString (); }
Tags: C# (C# 4.0)

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900