Thread: Problem with enigma machine

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    1

    Unhappy Problem with enigma machine

    I need help with homework from college, my teacher asked me a coder / decoder of enigma machine...
    I declared the Rotors:
    Code:
    char rotortop[26] = {'B','D','F','H','J','I','N','P','R','T','V','X','Z','A','C','E','G','I','K','M','O','Q','S','U','W','Y'};
    char rotormid[26] = {'E','J','O','T','Y','C','H','M','R','W','A','F','K','P','U','Z','D','I','N','S','X','B','G','L','Q','V'};
    char rotorbot[26] = {'G','N','U','A','H','O','V','B','I','P','W','C','J','Q','X','D','K','R','Y','E','L','S','Z','F','M','T'};
    I also need to make the code read a text file and I make this function but don't know if it is right

    Code:
    void descodificar(void){   
     printf("Entre com o texto que deseja descodificar: \n");   
     scanf("%c", &texto);    
    FILE *file;   
    file = fopen("TextoDescod2.txt", "w");    
    fprintf(file, "%c", texto);   
    //Algoritmo Enigma   
    fclose(file);}

    Basically, after the rotor complete the circle, the next rotor should start spinning and I can not do this.


    I don't know how to make this algorithm...

    Sorry for bad english, i'm from brazil... the comments is in portuguese...
    I appreciate the help.
    I need help with homework from college, my teacher asked me a coder / decoder machine
    Last edited by Matheus Melo; 10-08-2016 at 02:49 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,058
    Perhaps declare three indices

    int topPos, midPos, botPos;

    At some point in the code, you do
    Code:
    if ( ++topPos == 26 ) {
      topPos = 0;  // back to the beginning
      ++midPos;  // advance 1 step
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help solve this enigma, please
    By falcon758 in forum C Programming
    Replies: 25
    Last Post: 09-24-2011, 02:18 AM
  2. Enigma execpvp
    By simpatico_qa in forum C Programming
    Replies: 10
    Last Post: 05-11-2009, 03:04 PM
  3. a new enigma
    By caroundw5h in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-17-2004, 07:14 PM
  4. Help About The ENIGMA Algoritm
    By JohnnyAtomic in forum C Programming
    Replies: 4
    Last Post: 02-22-2002, 10:05 AM
  5. Another do-while enigma..for me
    By bugeye in forum C Programming
    Replies: 9
    Last Post: 01-26-2002, 09:24 AM

Tags for this Thread