A very good registration machine implementation code, and the market popular Istar menu.
Import Cocoa
Extension String {
Func md5numeric (), String? {
Let data = (self asNSString). datausingencoding (nsutf8stringencoding)
Let result = Nsmutabledata (Length:int (cc_md5_digest_length))
Let resultbytes = unsafemutablepointer<cunsignedchar> (result.mutablebytes)
ifdata = = Nil {
returnNil
}
CC_MD5 (data!. Bytes, Cc_long (data!. Length), resultbytes)
Let buffer = unsafebufferpointer<cunsignedchar> (start:resultbytes, Count:result.length)
var hash = nsmutablestring ()
var numerichash = nsmutablestring ()
forIinchBuffer {
Hash.appendformat ("%02x"I
}
forIinch0... hash.length-1{
Numerichash.appendformat ("%d", Hash.characteratindex (i))
}
Numerichash.replaceoccurrencesofstring (
"0",
Withstring:"",
Options:NSStringCompareOptions.CaseInsensitiveSearch,
Range:nsmakerange (0, Numerichash.length)
)
ifNumerichash.length < -{
returnNil
}
Let numerichashstring:string = Numerichash
Let StartIndex = Advance (Numerichashstring.startindex,5)
Let EndIndex = Advance (StartIndex,8)
Let range = Range (Start:startindex, End:endindex)
returnNumerichashstring[range]
}
}
Let ApplicationName ="IStat Menu 5.01"
Let pool ="0123456789"
LetConst="43917202"
classAppdelegate:nsobject, Nsapplicationdelegate {
Func fun (), String {
Let seed =0x39* Arc4random_uniform (175)
returnString (format:"%04d", seed)
}
@IBAction func Generate (Sender:anyobject) {
var seed =""
var saltseed =""
forIinch0...7{
Let C = pool[advance (Pool.startindex, Int (Arc4random_uniform (Ten)))]
Seed.append (c)
Saltseed.append (c)
Saltseed.append (Const[Advance (Const. StartIndex, i)])
}
Let checksum = Saltseed.md5numeric ()
ifChecksum = = Nil {
return
}
var result =""
Result.append (checksum![ Advance (checksum!. StartIndex,3)])
Result.append (Seed[advance (Seed.startindex,0)])
Result.append (Seed[advance (Seed.startindex,4)])
Result.append (checksum![ Advance (checksum!. StartIndex,7)])
Result + ="-"
Result.append (checksum![ Advance (checksum!. StartIndex,6)])
Result.append (checksum![ Advance (checksum!. StartIndex,4)])
Result.append (Seed[advance (Seed.startindex,2)])
Result.append (checksum![ Advance (checksum!. StartIndex,5)])
Result + ="-"
Result.append (Seed[advance (Seed.startindex,1)])
Result.append (Seed[advance (Seed.startindex,3)])
Result.append (checksum![ Advance (checksum!. StartIndex,1)])
Result.append (Seed[advance (Seed.startindex,5)])
Result + ="-"
Result.append (checksum![ Advance (checksum!. StartIndex,0)])
Result.append (Seed[advance (Seed.startindex,6)])
Result.append (Seed[advance (Seed.startindex,7)])
Result.append (checksum![ Advance (checksum!. StartIndex,2)])
Result + ="-"
Result + = Fun ()
Textfield.stringvalue = result
}
}
The implementation of the keygen is as follows (Istarmenu CORE Keygen)