Thread: Todays silly questions

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    808

    Todays silly questions

    First question is if i have a letter (A-Z or a-z) that i have xor'ed with another letter will the result always be less than the numeric value of the letters? i Think yes because the msb upto 127 is always 0 a 0 and a 0 xor'ed is 0 and a 1 and a 1 xor'ed is a o therefore the answer will always be smaller then the largest numeric equiverlant of the letters. Am i correct?


    second one is if i have an array is it always safe to go one past and test the element ie does the memory manager allow that extra space

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    In 4-bit binary, 1000 xor 0001 is 1001, which is higher than both inputs.
    However, if you are assuming ASCII (or first 128 chars of UTF-8) encoding and only letters then the result will always be less since the inputs always start 01... in binary, so the result will always start 00.... But in the Euler problem, the decoded text has punctuation, spaces, and numbers as well, and there's no reason it couldn't have newlines '\n' and/or tabs '\t' (and even carriage returns '\r' on Windows). The newline character is 00001010 which when xor'ed with 'a' which is 01100001 yields 01101011 which is larger than either.

    Note that they mention "common English words", so the method they are hinting at is to run through all 26-cubed = 17576 possible passwords, decode the text with each, and search for common English words like "the".

    if i have an array is it always safe to go one past and test the element ie does the memory manager allow that extra space
    No. You are never allowed to access outside of the allocated array memory and are not supposed to assume anything like that about the "memory manager" or the memory layout (e.g., what is just beyond the array data on the stack). There is never a need to do that, either, since if you really need to do that you could simply make the array 1 bigger.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    oh that wont work then i was going to use my own version of is print to use as a filter ie if its between 33 and 126 its a possible match but as i am ignoring anything below 33 i would loose the terminating \0 and therefore cant check the length against the encrypted text.

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,127
    Stop being so conservative with the size of an array! You have tons of memory to work with! If you need 5 bytes, make it an array of 20!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Todays headache
    By cooper1200 in forum C Programming
    Replies: 10
    Last Post: 06-01-2023, 11:20 AM
  2. Silly pointer questions
    By sillyquestion4u in forum C Programming
    Replies: 4
    Last Post: 06-20-2015, 08:41 PM
  3. Getting todays date in C?
    By shwetha_siddu in forum C Programming
    Replies: 1
    Last Post: 04-08-2009, 12:05 AM
  4. The History Of Todays Problem!!
    By GodLike in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 07-07-2002, 10:39 AM
  5. Todays time and date
    By wozza in forum C Programming
    Replies: 7
    Last Post: 05-27-2002, 03:42 PM

Tags for this Thread