0

Hi I was wondering if anyone can help me with the following question My attempt for part a is below. I don't understand why my procedure isn't working, it runs but then gives no values back when evaluating the procedure for part b. I have used the print command to check if the array is finding a match which it seems to be doing, but it looks like it is just ignoring it enter image description here

The protocol for baby step giant step is as follows

enter image description here

and the protocol for EL gamal is enter image description here

My procedure is as follows:

    proc3 := proc (alpha, beta, p)
    local k, R, i, j, N, A, t;
     description "baby step giant step procedure";
     N := floor(sqrt(p-1))+1;
     A := Array(0 .. N);
     for j from 0 to N do
     A[j] := `mod`(alpha^j, p)
     oo;
     for i from 0 to N do
     t := (beta*alpha^(-N*i))modp;
     for k from 0 to N do
     print(t, A[k]);
      if t = A*[k] then
      return k+N*i; 
      fi;
      od;
      od;
      end proc;

when i do proc3(3, 64, 137) it returns nothing so i put the print command in and now it gives

                                     64, 1
                         64, 3
                         64, 9
                         64, 27
                         64, 81
                        64, 106
                         64, 44
                        64, 132
                        64, 122
                         64, 92
                         64, 2
                         64, 6
                         64, 18
                         34, 1
                         34, 3
                         34, 9
                         34, 27
                         34, 81
                        34, 106
                         34, 44
                        34, 132
                        34, 122
                         34, 92
                         34, 2
                         34, 6
                         34, 18
                         78, 1
                         78, 3
                         78, 9
                         78, 27
                         78, 81
                        78, 106
                         78, 44
                        78, 132
                        78, 122
                         78, 92
                         78, 2
                         78, 6
                         78, 18
                         50, 1
                         50, 3
                         50, 9
                         50, 27
                         50, 81
                        50, 106
                         50, 44
                        50, 132
                        50, 122
                         50, 92
                         50, 2
                         50, 6
                         50, 18
                         18, 1
                         18, 3
                         18, 9
                         18, 27
                         18, 81
                        18, 106
                         18, 44
                        18, 132
                        18, 122
                         18, 92
                         18, 2
                         18, 6
                         18, 18
                          1, 1
                          1, 3
                          1, 9
                         1, 27
                         1, 81
                         1, 106
                         1, 44
                         1, 132
                         1, 122
                         1, 92
                          1, 2
                          1, 6
                         1, 18
                         99, 1
                         99, 3
                         99, 9
                         99, 27
                         99, 81
                        99, 106
                         99, 44
                        99, 132
                        99, 122
                         99, 92
                         99, 2
                         99, 6
                         99, 18
                         74, 1
                         74, 3
                         74, 9
                         74, 27
                         74, 81
                        74, 106
                         74, 44
                        74, 132
                        74, 122
                         74, 92
                         74, 2
                         74, 6
                         74, 18
                         65, 1
                         65, 3
                         65, 9
                         65, 27
                         65, 81
                        65, 106
                         65, 44
                        65, 132
                        65, 122
                         65, 92
                         65, 2
                         65, 6
                         65, 18
                         133, 1
                         133, 3
                         133, 9
                        133, 27
                        133, 81
                        133, 106
                        133, 44
                        133, 132
                        133, 122
                        133, 92
                         133, 2
                         133, 6
                        133, 18
                         15, 1
                         15, 3
                         15, 9
                         15, 27
                         15, 81
                        15, 106
                         15, 44
                        15, 132
                        15, 122
                         15, 92
                         15, 2
                         15, 6
                         15, 18
                         115, 1
                         115, 3
                         115, 9
                        115, 27
                        115, 81
                        115, 106
                        115, 44
                        115, 132
                        115, 122
                        115, 92
                         115, 2
                         115, 6
                        115, 18
                         14, 1
                         14, 3
                         14, 9
                         14, 27
                         14, 81
                        14, 106
                         14, 44
                        14, 132
                        14, 122
                         14, 92
                         14, 2
                         14, 6
                         14, 18

as you can clearly see the match is at 18,18 but for some reason it isnt taking this into account, can anyone see what i am doing wrong? its starting to become stressful. also how can we increase the efficiency of the procedure so it can calculate x for larger values of a,b and p. for part c i know i need to use the procedure from part a. Any help would be appreciated thanks for taking time to read this.

my procedure for part c is as follows

           Elgamal := proc (ciphy, hkt, p, a, b)
           local i, icdarray, s, q;
             icdarray := Array(5 .. 388);
               for i from 5 to 388 do 
               s := ciphy[i];
               q := `mod`(1/hkt^proc3(a, b, p), p);
               icdarray[i] := s*q;
               end do;
               return convert(icdarray, bytes);
              end proc;

where proc3 is as follows

                  proc3 := proc (alpha, beta, p)
               local k, R, i, j, N, A, t;
           Description "baby step giant step procedure";
             N := floor(sqrt(p-1))+1;
             A := Array(0 .. N);
             for j from 0 to N do
             A[j] := `mod`(alpha&^j, p);
            end do;
      for i from 0 to N do
         t := `mod`(beta*alpha&^(-N*i), p);
        for k from 0 to N do
        if t = A[k]
       then return k+N*i;
     end if; 
     end do; 
       end do; 
     end proc;

                  header := 9681348997

ciphertext: [12432485341, 2579085006, 13736574369, 4105371047, 9573017222,

7824534168, 10017411248, 13292180343, 2356887993, 9573017222,

10017411248, 13765667419, 9795214235, 10017411248, 2801282019,

608404939, 4105371047, 13765667419, 11572790339, 13765667419,

11765894302, 10017411248, 13765667419, 4549765073, 10017411248,

13736574369, 2579085006, 4549765073, 10017411248, 4549765073,

13765667419, 2801282019, 830601952, 4105371047, 10017411248,

7824534168, 13765667419, 13736574369, 2801282019, 7824534168,

10017411248, 830601952, 9573017222, 4327568060, 13765667419,

6076051114, 8268928194, 13292180343, 10017411248, 7824534168,

386207926, 2801282019, 4105371047, 2579085006, 6076051114,

608404939, 13765667419, 6076051114, 830601952, 13765667419,

4105371047, 11765894302, 10017411248, 13765667419, 13292180343,

13736574369, 10017411248, 608404939, 10017411248, 7824534168,

2134690980, 13765667419, 4105371047, 11765894302, 2801282019,

4105371047, 13765667419, 2579085006, 608404939, 13292180343,

11543697289, 2579085006, 7824534168, 10017411248, 4549765073,

13765667419, 4994159099, 5853854101, 6076051114, 830601952,

4327568060, 6076051114, 5853854101, 10017411248, 7824534168,

13765667419, 4105371047, 6076051114, 13765667419, 9573017222,

13292180343, 10017411248, 13765667419, 4105371047, 11765894302,

10017411248, 13765667419, 5853854101, 6076051114, 7824534168,

4549765073, 13765667419, 11572790339, 13765667419, 4105371047,

11765894302, 2801282019, 4105371047, 13765667419, 4105371047,

11765894302, 10017411248, 13765667419, 4327568060, 2801282019,

608404939, 4549765073, 13292180343, 13736574369, 2801282019,

11543697289, 10017411248, 13765667419, 5853854101, 2801282019,

13292180343, 13765667419, 11765894302, 6076051114, 7824534168,

7824534168, 2579085006, 8268928194, 4327568060, 2134690980,

13765667419, 11543697289, 7824534168, 10017411248, 13736574369,

2579085006, 11543697289, 2579085006, 4105371047, 6076051114,

9573017222, 13292180343, 2385981043, 13765667419, 3245676045,

9573017222, 2801282019, 2579085006, 608404939, 4105371047,

6105144164, 13765667419, 5853854101, 11765894302, 10017411248,

608404939, 13765667419, 9573017222, 13292180343, 10017411248,

4549765073, 13765667419, 4105371047, 6076051114, 13765667419,

4549765073, 10017411248, 13292180343, 13736574369, 7824534168,

2579085006, 8268928194, 10017411248, 13765667419, 4105371047,

11765894302, 10017411248, 13765667419, 6076051114, 13736574369,

13736574369, 2801282019, 13292180343, 2579085006, 6076051114,

608404939, 2801282019, 4327568060, 13765667419, 386207926,

2579085006, 4327568060, 4327568060, 2801282019, 6298248127,

10017411248, 13765667419, 4105371047, 11765894302, 7824534168,

6076051114, 9573017222, 6298248127, 11765894302, 13765667419,

5853854101, 11765894302, 2579085006, 13736574369, 11765894302,

13765667419, 4105371047, 11765894302, 10017411248, 2134690980,

13765667419, 11543697289, 2801282019, 13292180343, 13292180343,

10017411248, 4549765073, 6105144164, 13765667419, 9795214235,

10017411248, 2801282019, 608404939, 4105371047, 13765667419,

830601952, 10017411248, 386207926, 10017411248, 7824534168,

11572790339, 7824534168, 2579085006, 4549765073, 4549765073,

10017411248, 608404939, 13765667419, 2801282019, 608404939,

4549765073, 13765667419, 4105371047, 9573017222, 9795214235,

8268928194, 4327568060, 10017411248, 4549765073, 6076051114,

5853854101, 608404939, 2385981043, 13765667419, 4994159099,

5853854101, 6076051114, 830601952, 4327568060, 6076051114,

5853854101, 10017411248, 7824534168, 13765667419, 5853854101,

2801282019, 13292180343, 13765667419, 2801282019, 13765667419,

4105371047, 6076051114, 9573017222, 7824534168, 2579085006,

13292180343, 4105371047, 6105144164, 13765667419, 4105371047,

11765894302, 10017411248, 13765667419, 830601952, 2579085006,

7824534168, 13292180343, 4105371047, 13765667419, 10017411248,

386207926, 10017411248, 7824534168, 13765667419, 13292180343,

10017411248, 10017411248, 608404939, 13765667419, 6076051114,

608404939, 13765667419, 4105371047, 11765894302, 10017411248,

13765667419, 5438553125, 2579085006, 13292180343, 13736574369,

5853854101, 6076051114, 7824534168, 4327568060, 4549765073,

2385981043, 13765667419, 4994159099, 6076051114, 9573017222,

7824534168, 2579085006, 13292180343, 4105371047, 6105144164,

13765667419, 8713322220, 2579085006, 608404939, 13736574369,

10017411248, 5853854101, 2579085006, 608404939, 4549765073,

13765667419, 11765894302, 2801282019, 4549765073, 13765667419,

4549765073, 10017411248, 13736574369, 2579085006, 4549765073,

10017411248, 4549765073, 6105144164, 13765667419, 9795214235,

10017411248, 2801282019, 608404939, 4105371047, 13765667419,

8075824231, 2579085006, 4549765073, 2579085006, 6076051114,

4105371047, 8075824231, 2385981043]

acer
  • 6,671
  • 15
  • 15
Gibberish
  • 147
  • 9
  • As mentioned in an answer to another question of yours, use the syntax `&^` instead of `^` inside the mod call. Otherwise the potentially large and costly explicit powering is done before taking the mod. – acer Feb 24 '17 at 17:34
  • yeah thank you for this i forgot to place that inside there – Gibberish Feb 24 '17 at 17:35
  • Don't delete the important parts of your question (including the protocol details, etc) just because you don't want anyone else taking your course (or the instructor) to see the full story. – acer Feb 28 '17 at 02:46

1 Answers1

2

Your conditional test is if t = A*[k] then where you have made a typo since you want A[k] instead of that multiplication.

If you are using 2D Math input mode then a space in the input between A and [ would get parsed as implicit multiplication. If this was your case here, or if you repeatedly get caught out by that then consider switching to 1D Notation input mode (a GUI preference).

acer
  • 6,671
  • 15
  • 15
  • Thank you so much i cant belive i didnt spot that it works for the simple case of 60 now. thank you. – Gibberish Feb 24 '17 at 17:34
  • for part c the header is set to be h=9681348997 and the first part of the cipher text is 12432485341 i'm unsure on how i'm supposed to use part a to aid me doing it – Gibberish Feb 24 '17 at 18:02
  • also i cant seem to switch to 1D notation as it does not show up in the settings i use maple 17 – Gibberish Feb 24 '17 at 18:06
  • In the Maple 17 GUI for MS-Windows/Linux, from the main menubar, go to Tools->Options to launch the preferences popup. The choose the "Display" tab, and change the "Input display" item from "2-D Math Notation" to instead be "Maple Notation". Then in the "Interface" tab change the item "Default format for new worksheets:" from "Document" to "Worksheet". The hit the "Apply Globally" button at the bottom of the popup you're in. After all that the main menubar's "New" should open a Worksheet with 1-D input mode. You may find it easier to program in. ps. Did you delete your previous rsa Question? – acer Feb 24 '17 at 19:24
  • yeah thank you for this, and i just realised it was accidental. i just recovered it, sorry about that, i was trying to edit the question, all sorted now. also would we set up the procedure for this in the same way as the rsa or would we need to use an array? – Gibberish Feb 24 '17 at 19:55
  • Well, if say you find that k might be 57942 then you can operate on a Maple list of encoded blocks by using the `map` command to apply the decoding step (last bullet in your protocol) to each entry of that list. So, yes, no need for an array, to decode. – acer Feb 24 '17 at 22:07
  • Okay I will upload my attempt later if you care to see – Gibberish Feb 24 '17 at 23:22
  • hi i uploaded my attempt for part c could you see where i am going wrong? the cipher text i want to decrypt is below, 12432485341, 2579085006, 13736574369, 4105371047, 9573017222, however when i run it it takes ages to compute and crashes maple. could you also show me a procedure that can encrypt like you did for the rsa but with the elgamal protocol? – Gibberish Feb 26 '17 at 23:12
  • i added the cipher text to the post – Gibberish Feb 27 '17 at 12:26
  • Please see my solution to your (duplicate) question, which also explains why your attempt runs slow: http://www.mapleprimes.com/questions/221310-ELgamal-Procedure – acer Feb 27 '17 at 20:09