acer

32348 Reputation

29 Badges

19 years, 331 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

What do you intend the amplitude to represent? Power?

The body of this Question keeps being deleted. Here is the original title and question:

Crypt and decrypt with Vigenère

ConvertToNumbers:=proc(L::list)
local i,M;
M:=[];
for i from 1 to nops(L) do
M:=[op(M),StringTools[Ord](L[i])-96];
if M[i]>26 or M[i]<0 then M[i]:="Errore"; end if;
end do;
return M;
end proc;

ConvertToLetters:=proc(L::list)
local i,M;
M:=[];
for i from 1 to nops(L) do
if L[i]>26 or L[i]<0 then M:=[op(M),"Errore"]; end if;
M:=[op(M),StringTools[Char](L[i]+96)];
end do;
return M;
end proc;

I wrote this proc because i need to create an interactive component that crypt and decrypt with vigenere.
(procedures need lists)

"In a Caesar cipher, each letter of the alphabet is shifted along some number of places; for example, in a Caesar cipher of shift 3, A would become D, B would become E, Y would become B and so on. The Vigenère cipher consists of several Caesar ciphers in sequence with different shift values.

To encrypt, a table of alphabets can be used, termed a tabula recta, Vigenère square, or Vigenère table. It consists of the alphabet written out 26 times in different rows, each alphabet shifted cyclically to the left compared to the previous alphabet, corresponding to the 26 possible Caesar ciphers. At different points in the encryption process, the cipher uses a different alphabet from one of the rows. The alphabet used at each point depends on a repeating keyword.[citation needed]

For example, suppose that the plaintext to be encrypted is:

ATTACKATDAWN
The person sending the message chooses a keyword and repeats it until it matches the length of the plaintext, for example, the keyword "LEMON":

LEMON
Each row starts with a key letter. The remainder of the row holds the letters A to Z (in shifted order). Although there are 26 key rows shown, you will only use as many keys (different alphabets) as there are unique letters in the key string, here just 5 keys, {L, E, M, O, N}. For successive letters of the message, we are going to take successive letters of the key string, and encipher each message letter using its corresponding key row. Choose the next letter of the key, go along that row to find the column heading that matches the message character; the letter at the intersection of [key-row, msg-col] is the enciphered letter.

For example, the first letter of the plaintext, A, is paired with L, the first letter of the key. So use row L and column A of the Vigenère square, namely L. Similarly, for the second letter of the plaintext, the second letter of the key is used; the letter at row E and column T is X. The rest of the plaintext is enciphered in a similar fashion:

Plaintext:	ATTACKATDAWN
Key:	LEMON
Ciphertext:	LXFOPVEFRNHR
Decryption is performed by going to the row in the table corresponding to the key, finding the position of the ciphertext letter in this row, and then using the column's label as the plaintext. For example, in row L (from LEMON), the ciphertext L appears in column A, which is the first plaintext letter. Next we go to row E (from LEMON), locate the ciphertext X which is found in column T, thus T is the second plaintext letter."

I think that it can be done with a for loop but I do not know where to start.

Thanks in advance!

@Djboyko It's not clear what is in the DIMMatrix Matrix at the moment that the eigenvalues are computed. You call fprintf with %f format, but you are also calling `simplify`. Is the Matrix purely floating-point, when the eigenvalues are computed? If not then cannot you make it so, using evalf or evalhf?

Are you calling linalg[eigenvalues], and if so then why not LinearAlgebra:-Eigenvalues?

If the Matrix can be cast to purely floats, then is it symmetric? If so then casting the Matrix to one with shape=symmetric and datatype=float[8] will allow all the result to be purely real floats (and pre-sorted) if compute with LinearAlgebra:-Eigenvalues.

LinearAlgebra:-Eigenvalues wil also use hardware double-precision (by default, if Digits<=15). And linalg[eigenvalues] will only use something similar (an evalhf internal routine), and only if the input is all floats. But the former is faster because it uses a multi-threaded and optimized compiled LAPACK & BLAS. And only the former has a better variant for the symmetric case.

If the Matrix can be cast to purely floats (using evalf at least, say) then you'll also likely get a faster and more accurate and robust result than if you allow it to to an exact symbolic computation (where the exact symbolic results are turned into floats only when you invoke fprintf with the %f format).

I don't understand your 0.2 and 0.005 notation. Is that something related to accuracy, and if so then what does it mean?

Why not upload a worksheet that shows what the Matrix consists of? (Before `kx` and `ky` get realcons values would be OK).

How big is the Matrix?

When you say that you have to make an interactive component do you mean something that simply lets the user enter message and key in text-boxes, and which just displays the result in another text-box? In that scenario you'd mostly just need procedures that do the encryption and decryption.

Or do you mean something more illustrative of how the Vigenere cipher works? For example, something that shows (progressing character-by-character according to some button press, say) the column and row and intersection in a displayed graphical element containing the tabula recta?

@vv Ok, I now believe that the original expression is  -2*a^23*h^40*o*v^2 + 2*a^23*h^40*v^3 .

Sorry for being a doubter. I had to do it myself...   ;)

@roman_pearce I also submitted a bug report (on Feb 28). I believe that I reported seeing inconsistent behaviour in versions (each being final point-releases) back to 12.02.

@vv Are you sure that is the correct result?

@Markiyan Hirnyk The page you cite is about numeric formatting. I don't see how that would help this student in estimating the quantity by something that represents a (non-zero) floating-point value.

@Rouben Rostamian  Your suggestion is nice and simple.

And, in case the OP was wondering,

restart;

eqn := 1/4*x*(3-2*x)^2/(1-x)^3
       = 18325.73901+exp(36.58420421-10902.09286/T):
ee := (lhs-rhs)(eqn):

A:=fsolve(eval(ee,T=300)):
B:=fsolve(eval(ee,T=800)):

P := plot(rhs(isolate(ee,T)), x=A..B):

plots:-display(
   plottools:-reflect(P, [[0,0],[1,1]]),
   labels=[T, x], size=[500, 400]);

@Ronan I have submitted such a Software Change Request (SCR). Part of it relates to convenience (eg. supplying the rotation Matrix), and part to efficiency (esp. of internal plot structures under rotation/transformation).

ps. I might reiterate that vv's suggestion also seemed nice and convenient (to me), though using angles rather than an explicit rotation Matrix.

I should probably mention that I don't know what causes the different behavior. It might well be that it's related to memory state, say (and if so then perhaps not caused by a special 2-D Input per se, except to the extent that it affects the state).

@Ronan Yes, thanks for the interesting details. I've reread the prior responses now -- sorry about the Body2 attribution.

Please note that that the variant you cite (just above) from my Answer sheet attachment is quite inefficient (much more so than plottools:-rotate itself, which can turn lean float[8] rtable data into cumbersome listlists). I was really just trying to illustrate some other kinds of syntax would work for you (and in particular which allowed for Matrix `Rot` to be pushed in by name, say).

And with yet another way (somewhat of a cross bewteen my original and Rouben's).

equilibrium_alt2.mw

@Christopher2222There are more ways to rebind the name `changecoords` than just by loading the `plots` package. So your response is not wholly correct.

Using colon-dash before the name gets the global name, regardless. Wrap it in uneval quotes if you want something that guards against collision-with-a-local *and* assignment to the global, etc. 

Your last comment goes against the main thrust of your initial question.

First 285 286 287 288 289 290 291 Last Page 287 of 592