Skip to content

Instantly share code, notes, and snippets.

@qbatten
Last active June 3, 2017 20:01
Show Gist options
  • Save qbatten/56deba29527d7fed5e2951d5e148f1ad to your computer and use it in GitHub Desktop.
Save qbatten/56deba29527d7fed5e2951d5e148f1ad to your computer and use it in GitHub Desktop.
#define _XOPEN_SOURCE
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
int main (void)
{
// Initialize salt and check
string check = malloc(5);
check = " ";
string salt = "aaa";
// Get password and salt
printf("4-character password: ");
string pwd = malloc(5);
pwd = get_string();
//Check salt to ensure it's exactly 2 characters
while (strlen(salt) != 2)
{
printf("Salt: ");
salt = get_string();
}
string checkh = malloc(14);
checkh = crypt(check, salt);
printf("Check: %s\n", checkh);
// Get the hash
string pwdh = malloc(14);
pwdh = crypt(pwd, salt);
// Print
printf("pwd: %s\n", pwdh);
printf("chk: %s\n", checkh);
check = "ghgj";
checkh = crypt(check, salt);
printf("pwd: %s\n", pwdh);
printf("chk: %s\n", checkh);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment