fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. // Array 1: Alphanumeric characters (letters + digits)
  7. char alphanumeric[] = "abcdefghijklmnopqrstuvwxyz"
  8. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  9. "0123456789";
  10.  
  11. // Array 2: Special characters
  12. char special_chars[] = "!@#$%^&*()_+-=[]{}|;:,.<>?/~";
  13.  
  14. char get_random_char(char *array, int length);
  15. void shuffle_password(char *str, int length);
  16. void copy_to_clipboard(const char *text);
  17.  
  18. int main(void){
  19. char len_password;
  20. char password[18] = "";
  21.  
  22. srand(time(NULL));
  23. int len_alphanumeric = strlen(alphanumeric);
  24. int len_special_chars = strlen(special_chars);
  25.  
  26. printf("\n");
  27. printf(" ========================================\n");
  28. printf(" PhoenixPasswordGen v1.0 \n");
  29. printf(" ========================================\n");
  30. printf(" Created by Ph0en1x \n");
  31. printf(" ========================================\n");
  32. printf(" \n");
  33. printf(" Choose Password Length: \n");
  34. printf(" [1] ======== 8 symbols \n");
  35. printf(" [2] ================ 16 symbols \n");
  36. printf(" \n");
  37. printf(" ========================================\n");
  38. printf(" Enter your choice: ");
  39.  
  40. int choice;
  41. scanf("%d", &choice);
  42.  
  43. if (choice == 1) {
  44. len_password = 8;
  45. } else if (choice == 2) {
  46. len_password = 16;
  47. } else {
  48. printf("\n Invalid! Defaulting to 8 symbols.\n");
  49. len_password = 8;
  50. }
  51.  
  52. printf(" ========================================\n\n");
  53.  
  54. for(int i = 0; i <= len_password; ++i){
  55. char char_for_password = '0';
  56. if(i < len_password / 2){
  57. char_for_password = get_random_char(alphanumeric, len_alphanumeric);
  58. }
  59. else{
  60. char_for_password = get_random_char(special_chars, len_special_chars);
  61. }
  62. if(i == len_password){
  63. *(password + i) = '\0';
  64. break;
  65. }
  66. *(password + i) = char_for_password;
  67. }
  68.  
  69. shuffle_password(password, len_password);
  70.  
  71. printf("Your password is %s\n", password);
  72. printf("Remember or copy it!\n");
  73. return 0;
  74. }
  75.  
  76. char get_random_char(char *array, int length){
  77. int random_num = rand() % length;
  78. char random_char = *(array + random_num);
  79. return random_char;
  80. }
  81.  
  82. void shuffle_password(char *str, int length){
  83. for(int i = length - 1; i > 0; --i){
  84. int random_choice = rand() % length;
  85.  
  86. char temp = *(str + i);
  87. *(str + i) = *(str + random_choice);
  88. *(str + random_choice) = temp;
  89. }
  90. }
  91.  
Success #stdin #stdout 0s 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
  ========================================
         PhoenixPasswordGen v1.0         
  ========================================
              Created by Ph0en1x         
  ========================================
                                          
       Choose Password Length:           
       [1] ======== 8 symbols            
       [2] ================ 16 symbols   
                                          
  ========================================
   Enter your choice: 
  Invalid! Defaulting to 8 symbols.
  ========================================

Your password is >$#tw{fP
Remember or copy it!