summaryrefslogtreecommitdiff
path: root/assignment1/exercise1_1.c
diff options
context:
space:
mode:
Diffstat (limited to 'assignment1/exercise1_1.c')
-rw-r--r--assignment1/exercise1_1.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/assignment1/exercise1_1.c b/assignment1/exercise1_1.c
new file mode 100644
index 0000000..e1dd810
--- /dev/null
+++ b/assignment1/exercise1_1.c
@@ -0,0 +1,33 @@
+#include <stdint.h>
+#include <stdio.h>
+
+uint32_t modexp(uint32_t a, unsigned char e[4])
+{
+ /* TODO: implement */
+}
+
+/* Pipe output through sage */
+#define NTESTS 20
+int main(void)
+{
+ FILE *urandom = fopen("/dev/urandom", "r");
+ uint32_t a,r,ei;
+ unsigned char e[4];
+ int i,j;
+
+ for(i=0;i<NTESTS;i++)
+ {
+ fread(&a,sizeof(uint32_t),1,urandom);
+ fread(e,sizeof(unsigned char),4,urandom);
+ r = modexp(a,e);
+
+ ei = 0;
+ for(j=0;j<4;j++)
+ ei |= (uint32_t)e[j] << 8*j;
+
+ printf("power_mod(%u,%u,2^32) - %u\n", a,ei,r);
+ }
+
+ fclose(urandom);
+ return 0;
+}