4
$\begingroup$

I've loved mathematics for a very long time but am only now beginning my journey to learn to code. The attached image shows the two different outputs (out-5, out 6) for a simple crypto-cypher I'm trying to program. The copy and paste flexibility (without quotes) is important for the development of the program but I can't for the life of me tell what is causing the difference or what to do about it. I've spent nearly three days trying to troubleshoot it myself and would appreciate any insights the community may have.

Updated:

I've updated the question for clarity with the most relevant part of the code. I've investigated the answers so far and dug deep into the function with Head[] but the issue continues. How can I update the string to the proper set of digits MMA online wants?

j = InputForm[ToString[#]] & /@ {1B9C0,7C3E0,F87C0,37380,1064A0,45060,A5A80,A5A80}
{"B9C0","7 C3E0","F87C0","37380","1064 A0","45060","A5A80","A5A80"}

Interpreter["HexInteger"][j]
{Failure[\[WarningSign] Message:    Enter a valid number. Tag:  InterpretationFailure

ff = FromDigits[#, 16] & /@ j
FromDigits::nlst The expression"F87C0" is not a list of digits or a string of valid digits.
{FromDigits["B9C0",16],FromDigits["7 C3E0",16],FromDigits["F87C0",16],FromDigits["37380",16],FromDigits["1064 A0",16],FromDigits["45060",16],FromDigits["A5A80",16],FromDigits["A5A80",16]}
$\endgroup$
  • 2
    $\begingroup$ Please do not post images of your work, especially when the images display at a size that make them difficult to read. Please post your actual Mathematica code in the form of text that can be copied and pasted into a Mathematica notebook. Without such, it will be difficult to reproduce your problem and to experiment with possible solutions. $\endgroup$ – m_goldberg Jul 2 '17 at 1:26
  • $\begingroup$ @m_goldberg You're 100% correct. I'm really sorry. I'm just really new at this and still figuring it out. (There must be a function that will automatically put quotes around each of those strings in ln-5 no?) I'm just trying to work through your answer before accepting. But really – thank you very much for the help. $\endgroup$ – BBirdsell Jul 2 '17 at 2:25
  • $\begingroup$ I am quite mystified about how you made a copy that was not pasted into an input cell input form, which would have shown the quotes. It is possible to paste in output form by using Edit > Copy As > Plain Text, but that takes a special effort. $\endgroup$ – m_goldberg Jul 2 '17 at 2:36
  • $\begingroup$ @m_goldberg Do you think it might have something to do that I'm 100% in the cloud? $\endgroup$ – BBirdsell Jul 2 '17 at 14:02
  • 1
    $\begingroup$ I have no experience with any of Wolfram's cloud products, but you may be right about that making a difference in what a copy operation picks up. Perhaps someone with cloud experience can confirm your conjecture. The important point is that when you paste strings into an input cell you should see the quoted form. $\endgroup$ – m_goldberg Jul 2 '17 at 14:18
5
$\begingroup$

It looks to me that when you copied you copied the plain text form not the input form of the list of strings representing your hexadecimal numbers. Normally, copying form output cells gives the input form of the expression being copied, so I somewhat surprised that you got plain text. Here is how it should have gone.

ascii = ToExpression[LetterNumber["oasis"]]

{15, 1, 19, 9, 19}

b = 78334;
IntegerString[b ascii, 16]

{11ede2, 131fe, 16b5da, ac1ee, 16b5da}

The list was put into the next expression by copy and paste. Note the number strings are quoted. If you don't see the quotes, you know something went wrong with the copying.

FromDigits[#, 16] & /@ {"11ede2", "131fe", "16b5da", "ac1ee", "16b5da"}/b

{15, 1, 19, 9, 19}

$\endgroup$
4
$\begingroup$

Welcome to the world of coding! Objects like numbers and words have different types in programming languages like Mathematica. It's important to pay attention to the types of the objects you create. IntegerString returns a String type as output. Normally when a string is used as input it is entered surrounded by "double quotes" but when a String is printed on output, the quotes don't show. Should you copy/paste. without the quotes, the thing you create on input will be an ordinary Symbol type, which is different than a string. FromDigits wants a String or a List, as the error tells you.

One solution is to right click the cell and say ConvertTo->RawInputForm. That will add the double quotes and you can copy/paste safely.

$\endgroup$
  • $\begingroup$ I love Mathematica's ability to deploy simple scripts to a webpage automatically. The three days of troubleshooting mentioned in the OP refer to my time trying to use the "Head[]" function to sort out what was going on. All no no avail. As this gets developed, I plan to use it as a science-engagement education tool for kindergarten/ 1st grade students (with the help from their parents). So I really want the output to look as "science-fictiony" as possible (without quotes) and just add them on the decoding portion automatically if possible. Is there anything else helpful I can provide? $\endgroup$ – BBirdsell Jul 2 '17 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.