I have one python script which i am trying to convert and stuck in one place and unable to proceed. Please check where ever i have mentioned "Stuck here" in below code. any help would be appreciated
Original Python script:
import hashlib
meid = raw_input("Enter an MEID: ").upper()
s = hashlib.sha1(meid.decode('hex'))
#decode the hex MEID (convert it to binary!)
pesn = "80" + s.hexdigest()[-6:].upper()
#put the last 6 digits of the hash after 80
print "pESN: " + pesn
My C# conversion:
UInt64 EsnDec = 2161133276;
string EsnHex=string.Format("{0:x}", EsnDec);
string m = Convert.ToString(Convert.ToUInt32(EsnHex, 16), 2);
/*---------------------------------------------
Stuck here. Now m got complete binary data
and i need to take last 6 digits as per python
script and prefix "80".
---------------------------------------------*/
Console.WriteLine(m);
Console.Read();
Use String.Substring:
// last 6 characters
string lastsix = m.Substring(m.Length - 6);
Console.WriteLine("80{0}", lastsix);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With