Thread: Urgent Help Required

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    7

    Help in Cryptographic analysis

    This is the question -----

    Introduction

    Cryptographic analysis makes extensive use of the frequency with which let-
    ters and letter sequences occur in a language. If an encrypted text is known
    to be in english, for example, a great deal can be learned from the fact that
    the letters E, L, N, R, S, and T are the most common ones used in written
    english. Even more can be learned if common letter pairs, triplets, etc. are
    known.
    For this problem you are to write a program which accepts as input a
    text file of unspecified length and performs letter frequency analysis on the
    text. The program will report the five most frequent letters used in the text.

    The Input

    The input for this program will be contained in a file called: data.txt and
    will be stored in the same directory as your .cpp files. Please hard code this
    into your assignment.
    Your program should consider alphabetic characters only, and case should
    be ignored (e.g. an ‘a’ is the same as an ‘A’).

    The Output

    A report should be produced using the format shown in the example at
    the end of this problem description. The report should list the letters and
    their frequency in descending order of frequency. If there are several letters
    with the same frequency then these should be listed in alphabetical order as
    shown. Finally, if there are less than five distinct letter frequencies in a text,
    simply report as many distinct frequencies as possible. After this report,
    your program should terminate.

    Sample Input

    When a text file containing simply the line
    Peter Piper Picks Pickles!
    is used as input, the output should appear as shown below.
    Sample Output
    p (5)
    e (4)
    i (3)
    c (2)
    k (2)



    I have been given a project which is due this week. I have tried my best but i couldn't come up with a right answer, as my program can't compile with too many errors. Urgent help needed.
    I just want someone to give me an idea on how this program can be done.
    Thanks
    Last edited by rahully2j; 04-27-2011 at 04:05 AM.

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    7
    Anyone? make it fast.
    Last edited by rahully2j; 04-27-2011 at 04:12 AM.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I remember doing this assignment. I read the information here and then I was able to do it myself.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    7
    I read that before. I m not asking anyone to send me the program, that would be my loss as i won't learn anything. I just wanted an idea on how to get this done. So, if you can guide me that would be helpful.

  5. #5
    Registered User inequity's Avatar
    Join Date
    Nov 2010
    Location
    Seattle, Washington
    Posts
    59
    The introduction to the assignment made it sound really advanced, I was going to suggest markov chains and maps, but since you're only finding the frequency of individual characters in a text, here's some pseudo code

    Create an array the size of the alphabet and fill it with zeroes

    Open the file
    Read in a character
    Increment the according index in the array // so if it was a, array[0] += 1

    Use some kind of simple sorting to figure out the most common letters used (for example you could run 5 iterations of a bubble sort)
    Or you could just write some hard coded thing to just run through and find the five highest numbers and store their indexes

    print out the letters associated with the highest values, along with their frequency

    now go do that in code

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    7
    thanks brother...I'll post the code soon, if i have any problem.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How hard can it be to just open a file, read characters, and print them?
    If you can do that much, you're half-way there.

    The other half is just being able to count them.

    Try a simplified program and post what you manage to achieve.
    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.

  8. #8
    Registered User
    Join Date
    Apr 2011
    Posts
    7
    bruv for you it's all easy. You must be having like 3-5 years or even higher experience but i don't have any prerequisite knowledge in c++. I just started like last month, and this is my 4th assignment. I did well in others but this one is hard, you don't realize, 62% failure rate in c++ 1st year. So, i guess you can understand.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    62% sounds like a good start at weeding out the wannabe programmers. Perhaps now it's your turn?

    You said you had a program with lots of errors, well posting that would be a start.
    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.

  10. #10
    Registered User
    Join Date
    Apr 2011
    Posts
    7
    hey salem, i m still doing the program but could you please delete this thread? I mean many students are searching the question on google [putting the same question] to get a response. So, if you type the question this link comes up 1st. And "inequality" has already given me a hint on how to do this, so if others find out i'll be at disadvantage. I'll post another thread with different name, and will paste my program so you can check.

  11. #11

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I'm thinking of creating more accounts here just so I can "like" the previous post some more!
    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.

  13. #13
    Registered User
    Join Date
    Apr 2011
    Posts
    7
    Enough with the sarcasm already, or do 1 thing delete your post where you gave me the idea. That would be alright.

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by rahully2j
    And "inequality" has already given me a hint on how to do this, so if others find out i'll be at disadvantage.
    No, if others find out they will not be at a disadvantage. They could well ask a question and also get such a hint.

    Quote Originally Posted by rahully2j
    do 1 thing delete your post where you gave me the idea
    All I'm going to do is close this thread. You can stop being selfish now.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. urgent help required.
    By theabc in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2011, 11:04 AM
  2. help required urgent!!
    By ikj in forum C++ Programming
    Replies: 2
    Last Post: 05-28-2009, 10:15 AM
  3. Urgent Help required.. pls help ??
    By intruder in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2003, 01:05 PM
  4. urgent help required
    By Nadia in forum C Programming
    Replies: 4
    Last Post: 12-10-2002, 06:10 AM
  5. Urgent help required
    By sweets in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2002, 01:17 PM

Tags for this Thread