Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wargames.MY 2015 - Challenge 7 Base64 String
LyoNCiAqIFRoaXMgZmlsZSBoYXMgYmVlbiBjb21tZW50ZWQgdG8gc3VwcG9ydCBWaXN1YWwgU3R1ZGlvIEludGVsbGlzZW5zZS4NCiAqIFlvdSBzaG91bGQgbm90IHVzZSB0aGlzIGZpbGUgYXQgcnVudGltZSBpbnNpZGUgdGhlIGJyb3dzZXItLWl0IGlzIG9ubHkNCiAqIGludGVuZGVkIHRvIGJlIHVzZWQgb25seSBmb3IgZGVzaWduLXRpbWUgSW50ZWxsaVNlbnNlLiAgUGxlYXNlIHVzZSB0aGUNCiAqIHN0YW5kYXJkIGpRdWVyeSBsaWJyYXJ5IGZvciBhbGwgcHJvZHVjdGlvbiB1c2UuDQogKg0KICogQ29tbWVudCB2ZXJzaW9uOiAxLjMuMmINCiAqLw0KDQovKg0KICogalF1ZXJ5IEphdmFTY3JpcHQgTGlicmFyeSB2MS4zLjINCiAqIGh0dHA6Ly9qcXVlcnkuY29tLw0KICoNCiAqIENvcHlyaWdodCAoYykgMjAwOSBKb2huIFJlc2lnDQogKg0KICogUGVybWlzc2lvbiBpcyBoZXJlYnkgZ3JhbnRlZCwgZnJlZSBvZiBjaGFyZ2UsIHRvIGFueSBwZXJzb24gb2J0YWluaW5nDQogKiBhIGNvcHkgb2YgdGhpcyBzb2Z0d2FyZSBhbmQgYXNzb2NpYXRlZCBkb2N1bWVudGF0aW9uIGZpbGVzICh0aGUNCiAqICJTb2Z0d2FyZSIpLCB0byBkZWFsIGluIHRoZSBTb2Z0d2FyZSB3aXRob3V0IHJlc3RyaWN0aW9uLCBpbmNsdWRpbmcNCiAqIHdpdGhvdXQgbGltaXRhdGlvbiB0aGUgcmlnaHRzIHRvIHVzZSwgY29weSwgbW9kaWZ5LCBtZXJnZSwgcHVibGlzaCwNCiAqIGRpc3RyaWJ1dGUsIHN1YmxpY2Vuc2UsIGFuZC9vciBzZWxsIGNvcG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