Created
February 27, 2023 22:13
-
-
Save Bonney/5cc85f41cdeb80146c7d5169ded8aecd to your computer and use it in GitHub Desktop.
Generating Windows 95 OEM product keys, using Swift, for the heck of it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Inspired by this Hacker News comment: | |
| // https://news.ycombinator.com/item?id=34954579 | |
| // | |
| // OEM Windows 95 keys came in the form of XXXXX-OEM-00YYYYY-ZZZZZ. The XXXXX grouping represents when Microsoft issued the key by day-of-year and year, and the operating system would validate any number where the first three numbers range from 001 to 365 (or 366 for year 96), and the last two X digits were 95-99. The YYYYY group must be a multiple to 7, excluding the number 0. The ZZZZZ group is basically noise and anything is permissible in them. | |
| // | |
| // Now you can run a Windows 95 keygen in your head. You're welcome :) | |
| // | |
| import Foundation | |
| import Swift | |
| class Windows95KeyGenerator { | |
| init() { | |
| } | |
| // OEM Windows 95 keys came in the form of XXXXX-OEM-00YYYYY-ZZZZZ | |
| func generateWindows95Key() -> String { | |
| let generatedKey: String = (keyX() + "-OEM-" + keyY() + "-" + keyZ()).uppercased() | |
| return generatedKey | |
| } | |
| // The XXXXX grouping represents when Microsoft issued the key by day-of-year and year, and the operating system would validate any number where the first three numbers range from 001 to 365 (or 366 for year 96), and the last two X digits were 95-99 | |
| func keyX() -> String { | |
| let year: Int = Int.random(in: 95...99) // 95 - 99 | |
| let daysInYear: Int = (year == 96) ? 366 : 365 // 365, or 366 for '96 | |
| let yearString: String = String(year) | |
| let day: Int = Int.random(in: 1...daysInYear) // 1 - 365/366 | |
| let dayString: String = String(format: "%03d", day) // String padded with zeroes; "001", "002", "003"... | |
| return (dayString + yearString) | |
| } | |
| // The 00YYYYY group must be a multiple to 7, excluding the number 0 | |
| func keyY() -> String { | |
| let randomMultipleOf7 = Int.random(in: 1...14285) * 7 // 7 * 14,285 = 99,995, largest 5-character-long multiple of 7 | |
| let randomMultipleString: String = String(format: "%07d", randomMultipleOf7) // Pad out to 7 characters | |
| return randomMultipleString | |
| } | |
| // The ZZZZZ group is basically noise and anything is permissible in them | |
| func keyZ() -> String { | |
| let characters: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
| let randomCharacters: [String] = (0..<5).map { _ in | |
| String(characters.randomElement() ?? Character("X")) | |
| } | |
| let randomString: String = randomCharacters.joined(separator: "") | |
| return randomString | |
| } | |
| } | |
| let generator = Windows95KeyGenerator() | |
| generator.generateWindows95Key() | |
| for i in 0..<20 { | |
| print(generator.generateWindows95Key()) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment