注册机的实现如(istarMenu CORE Keygen)

一个非常好的注册机实现代码,而且市场流行的 istar menu 的。

 

 

import Cocoa

extension String {
    
    func MD5Numeric() -> String? {
        
        let data        = (self as NSString).dataUsingEncoding(NSUTF8StringEncoding)
        let result      = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH))
        let resultBytes = UnsafeMutablePointer<CUnsignedChar>(result.mutableBytes)
        
        if data == nil {
            return nil
        }
        
        CC_MD5(data!.bytes, CC_LONG(data!.length), resultBytes)
        
        let buffer      = UnsafeBufferPointer<CUnsignedChar>(start: resultBytes, count: result.length)
        var hash        = NSMutableString()
        var numericHash = NSMutableString()
        
        for i in buffer {
            hash.appendFormat("%02x", i)
        }
        
        for i in 0...hash.length-1 {
            numericHash.appendFormat("%d", hash.characterAtIndex(i))
        }
        
        numericHash.replaceOccurrencesOfString(
            "0",
            withString: "",
            options: NSStringCompareOptions.CaseInsensitiveSearch,
            range: NSMakeRange(0, numericHash.length)
        )
        
        
        if numericHash.length < 14 {
            return nil
        }
        
        let numericHashString: String = numericHash
        
        let startIndex  = advance(numericHashString.startIndex, 5)
        let endIndex    = advance(startIndex,                   8)
        let range       = Range(start: startIndex, end: endIndex)
        
        return numericHashString[range]
    }
    
}

let applicationName = "iStat Menu 5.01"

let pool            = "0123456789"
let const           = "43917202"

class AppDelegate: NSObject, NSApplicationDelegate {
    
    func fun() -> String {
        let seed = 0x39 * arc4random_uniform(175)
        return String(format: "%04d", seed)
    }
    
    @IBAction func generate(sender : AnyObject) {
        
        var seed        = ""
        var saltSeed    = ""
        for i in 0...7 {
            let c = pool[advance(pool.startIndex, Int(arc4random_uniform(10)))]
            seed.append(c)
            saltSeed.append(c)
            saltSeed.append(const[advance(const.startIndex, i)])
        }
        
        let checksum = saltSeed.MD5Numeric()
        
        if checksum == 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
    }
    
}

 

 

 

posted @ 2014-12-04 10:50  夏了′夏天  Views(445)  Comments(0Edit  收藏  举报