Skip to content

Instantly share code, notes, and snippets.

@hasherezade
Created April 1, 2016 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasherezade/785f7da52dfd91fe9e59ae283df2e898 to your computer and use it in GitHub Desktop.
Save hasherezade/785f7da52dfd91fe9e59ae283df2e898 to your computer and use it in GitHub Desktop.
Petya ransomware - supplied key encoder
bool encode(char* key, BYTE *encoded)
{
if (!key || !encoded) {
printf("Invalid buffer\n");
return false;
}
size_t len = strlen(key);
if (len < 16) {
printf("Invalid key\n");
return false;
}
if (len > 16) len = 16;
int i, j;
i = j = 0;
for (i = 0, j = 0; i < len; i++, j += 2) {
char k = key[i];
encoded[j] = k + 'z';
encoded[j+1] = k * 2;
}
encoded[j] = 0;
encoded[j+1] = 0;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment