35 Reputation

4 Badges

6 years, 185 days

MaplePrimes Activity

These are questions asked by adrian5213

This is the coding till i do dhe decryption process. 

Do(plaintextInt = convert(plaintext, bytes));
Do(plaintextBin = `~`[convert](plaintextInt, binary));
Do(plaintextBin2 = map2(nprintf, "%07d", plaintextBin));
Do(n0 = plaintextBin2[]);
Do(length1 = length(n0));
Do(plaintextCode = cat("", plaintextBin2[]));
Do(length2 = length(plaintextCode));
Do(z = convert(plaintextCode, decimal, binary));
Do(z1 = z+1);
Do(z2 = z1+%sk1);
Do(z3 = convert(z2, base, 2));
Do(b = cat("", z3[]));
Do(z4 = length(b));
Do(z5 = [Bits:-GetBits(-z2, -1 .. 0, bits = z4)]);
Do(z6 = cat("", z5[]));
Do(z7 = convert(z6, decimal, binary));
Do(%C = `mod`(Power(z7, %txte), %txtN));
Do(%C1 = `mod`(Power(%sk1, %txte), %txtN));

Do(%m = `mod`(Power(%C, %d), %N));


Then nw i need to decrypt back to the original message with the coding:

Do(z8 = [Bits:-GetBits(-%m,-1 .. 0, bits = z4)]);
Do(c = cat("", z8[]));
Do(z9 = convert(c, decimal, binary));
Do(z10 = z9-sk2);
Do(z11 = z10-1);
Do(z12 = [Bits:-GetBits(z11, -1 .. 0, bits = length2)]);
Do(d = cat("", z12[]));
Do(plaintextBin2 = [StringTools:-LengthSplit(d, length1)]);
Do(plaintextInt2 = `~`[convert](plaintextBin2, decimal, binary));
Do(%message1 = convert(plaintextInt, bytes));

when i execute the program it shows the error

so how should I solve this as although i think that it should be problem of parsing the number z4 in the sentence that i highlighed, but whenever i correct it it still can't work.Thus anyone who know please help.Thanks.


I need to do Huffman Coding by using Document Tools thus i can produce user interface by using coding that referred in this post by Alec Mihailovs. Below is the coding and Document Tools interface:

Do(Freq = proc (message) options operator, arrow; map(proc (x) options operator, arrow; rhs(x) = lhs(x) end proc, {StringTools:-CharacterFrequencies(message)}) end proc);
Do(Fr = Freq(plaintext));
Do(HuffmanTree = proc (message) options operator, arrow; if nops(message) <= 1 then rhs(message[]) else procname(`union`(message[3 .. -1], {lhs(message[1])+lhs(message[2]) = [rhs(message[1]), rhs(message[2])]})) end if end proc);
Do(HT = HuffmanTree(Fr));
Do(HuffmanCoding = proc (message, r := "") if message::string then message = r else procname(message[1], cat(r, 0)), procname(message[2], cat(r, 1)) end if end proc);
Do(HD = HuffmanCoding(HT));
Do(C = table([HD]));
Do(HC = cat(map(proc (x) options operator, arrow; C[x] end proc, StringTools:-Explode(message))[])

It still can get result for first part of the coding.During execute the second part of the coding(as bolded), it produces error ,the error show below.So how should I modified so that the error won't pop out @Alec Mihaivols


Coding in key generation of RSA Cryptosystem

message :=123456;

u := nextprime(RandomTools[Generate](integer(range = 10^100 .. 10^(110-1))));

v := nextprime(RandomTools[Generate](integer(range = 10^100 .. 10^(110-1))));

N := u*v;

phi := (u-1)*(v-1);

In RSA cryptosystem, the encryption or decryption of message only can be existed between range 1<=message<=N. This means that if the value of message bigger than N value then we can't get back the original value when performing decryption.Thus, wanna to ask that how can we create a coding so that the system will recognise the random integer u and v whether lie between range 1<=message<=N, means wanna crete a coding that if  N>=message then it will continue to the phi step whereas if message>=then the system need to regenerate the u and v until it satisfy the condition  1<=message<=N .Thus please help as i am a beginner in Maple.Thanks.

This is my source code to perform several binary arithmetic and HUffman Compression

Freq := proc (s) options operator, arrow; map(proc (x) options operator, arrow; rhs(x) = lhs(x) end proc, {StringTools:-CharacterFrequencies(s)}) end proc; s := readstat("x will be assigned "); Fr := Freq(s);

{1 = "a", 1 = "g", 1 = "l", 1 = "o"}

HuffmanTree := proc (s) options operator, arrow; if nops(s) <= 1 then rhs(s[]) else procname(`union`(s[3 .. -1], {lhs(s[1])+lhs(s[2]) = [rhs(s[1]), rhs(s[2])]})) end if end proc; HT := HuffmanTree(Fr);

[["a", "g"], ["l", "o"]]

HuffmanCoding := proc (s, p := "") if s::string then s = p else procname(s[1], cat(p, 0)), procname(s[2], cat(p, 1)) end if end proc; HC := HuffmanCoding(HT);

"a" = "00", "g" = "01", "l" = "10", "o" = "11"

C := table([HC]); b := cat(map(proc (x) options operator, arrow; C[x] end proc, StringTools:-Explode(s))[]);


# Begin the procedure with make string to integer
z := parse(b);

                                                                   100111    #Should be 00100111 after parsing

# Step 1:add 1 to z
binaryAdd := proc (z, y) options operator, arrow; convert(convert(z, decimal, 2)+convert(y, decimal, 2), binary) end proc;
z1 := binaryAdd(z, 1);


# Step 2: Reverse the number from left to right
z2 := convert(z1, base, 10);

[0, 0, 0, 1, 0, 1]

z3 := (parse@cat@op)(z2);

                                                                101  #Should be 000101 after parsing

 # Step 3: Addition between the first secret key and the Huffman Code


p := rand(0 .. 2^(length(z3)-2)):

rn := convert(p(), binary);


z4 := binaryAdd(z3, rn);


# Step 4:Obtain 2's complement

s := length(z4);

z5 := convert(z4, decimal, binary);


z6 := [Bits:-GetBits(-z5, -1 .. 0, bits = s)];

[0, 1, 0]

z7 :=(parse@cat@op)(z6);

                                                       10  # Should be 010 after passing


The Bold part is MAPLE answer. My problem for this MAPLE source code is the underlined answer  as I can't get the answer I need after I have my parsing of string or list. Do this problem can be solved or it is impossible to make the leading zero all the way of the process. I try to figure it out for several solution but it still the same results. Thus hope some experts or someone can help me solve it together. Appreciated if get solved.

Maple Coding:

z4:=11000010010000 (in binary form)

s = length(z4);




[Bits:-GetBits(-%, -1 .. 0, bits = s)];

z5 := subsop(1 = 0, %);

z6 := (`@`(`@`(parse, cat), op))(z5)

Suppose after two's complement of 11000010010000 will be 00111101110000 but when i parse it down it will become 11110110000 which two 0's bit is disappeared,how i can get back the original answer in maple?Thanks

1 2 Page 1 of 2