Thread: I don't understand how to do this function.

  1. #1

    Unhappy I don't understand how to do this function.

    I need some help writing a function that can crack a code. It needs to tell me what the most common letter is using the code, and list all the way to the least common letter. Help me please!
    (The code is a encode and decode)
    I understand I need to use and aray with the 26 letters and elements, but I don't understand what I need to do from there.


  2. #2
    Join Date
    Aug 2001
    Groningen (NL)
    You need a (large) number of valid codes. Only then you can determine which letter is most common. Since I don't know which encryption algorithm is used, I cannot tell you anything about how the crack the code. Well, you can use brute force attack: Just try any possible code.

  3. #3
    declare an array of 26 ints all intialized to zero
    change all letters in the message to either upper or lower case
    look at each char in the text one by one.
    use a switch based on the char you are evaluating
    if the char is an a (or an A) then increment array[0]
    if the char is a b (or a B) then increment array[1]

    when you're done looking at each char in the message the values stored in the array represent the number of times a given letter is used in the message where a corresponds to index 0, b to index 1, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM