fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void ordinals(const char *string, int *result, int *size) {
  5. *size = 0;
  6. while (*string) {
  7. result[(*size)++] = (int)(*string++);
  8. }
  9. }
  10.  
  11. void encode(const int *ords_list, int size, int *result) {
  12. for (int i = 0; i < size; i++) {
  13. result[i] = ords_list[i] ^ 'a';
  14. }
  15. }
  16.  
  17. void characters(const int *ords_list, int size, char *result) {
  18. for (int i = 0; i < size; i++) {
  19. result[i] = (char)ords_list[i];
  20. }
  21. result[size] = '\0'; // Null-terminate the string
  22. }
  23.  
  24. int main() {
  25. int encrypted_flag[] = {54, 9, 8, 18, 17, 4, 19, 4, 5, 53, 14, 15, 4, 18};
  26. int decoded_flag[14];
  27. char flag[15]; // Adjust size for null terminator
  28. int size;
  29.  
  30. encode(encrypted_flag, 14, decoded_flag);
  31. characters(decoded_flag, 14, flag);
  32.  
  33. char attempt[100]; // Buffer for user input
  34. printf("enter passphrase here: ");
  35. fgets(attempt, sizeof(attempt), stdin);
  36. attempt[strcspn(attempt, "\n")] = 0; // Remove newline character
  37.  
  38. if (strcmp(attempt, flag) == 0) {
  39. printf("congratulations, welcome to the secret program!\n");
  40. } else {
  41. printf("incorrect passphrase\n");
  42. }
  43.  
  44. return 0;
  45. }
  46.  
  47.  
Success #stdin #stdout 0.01s 5288KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
enter passphrase here: incorrect passphrase