Advertisement
Guest User

IDEA_microblaze

a guest
Dec 5th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.96 KB | None | 0 0
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * Use of the Software is limited solely to applications:
  16. * (a) running on a Xilinx device, or
  17. * (b) that interact with a Xilinx device through a bus or interconnect.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. *
  27. * Except as contained in this notice, the name of the Xilinx shall not be used
  28. * in advertising or otherwise to promote the sale, use or other dealings in
  29. * this Software without prior written authorization from Xilinx.
  30. *
  31. ******************************************************************************/
  32.  
  33. /*
  34.  * helloworld.c: simple test application
  35.  *
  36.  * This application configures UART 16550 to baud rate 9600.
  37.  * PS7 UART (Zynq) is not initialized by this application, since
  38.  * bootrom/bsp configures it to baud rate 115200
  39.  *
  40.  * ------------------------------------------------
  41.  * | UART TYPE   BAUD RATE                        |
  42.  * ------------------------------------------------
  43.  *   uartns550   9600
  44.  *   uartlite    Configurable only in HW design
  45.  *   ps7_uart    115200 (configured by bootrom/bsp)
  46.  */
  47.  
  48. #include <stdio.h>
  49. #include <string.h>
  50. #include "platform.h"
  51. #include "xil_printf.h"
  52.  
  53. //int modInverse(int a, int m)
  54. //{
  55. //  int m0 = m, t, q;
  56. //  int x0 = 0, x1 = 1;
  57. //
  58. //  if (m == 1)
  59. //      return 0;
  60. //
  61. //  while (a > 1) {
  62. //      q = a / m;
  63. //      t = m;
  64. //      m = a % m;
  65. //      a = t;
  66. //      t = x0;
  67. //      x0 = x1 - q * x0;
  68. //      x1 = t;
  69. //  }
  70. //
  71. //  return x1;
  72. //}
  73.  
  74. unsigned short int modInverse(unsigned short int a, unsigned short int m)
  75. {
  76.     a = a%m;
  77.     for (unsigned short int x=1; x<m; x++)
  78.        if ((a*x) % m == 1)
  79.           return x;
  80. }
  81.  
  82. int main()
  83. {
  84.     init_platform();
  85.  
  86.     unsigned short int Keys[60];
  87.     unsigned short int inversedKeys[60];
  88.     int i;
  89.     char c;
  90.     const int MOD = 65537;
  91.     char *str = "RWoM6zqNvL3J+nZVJhRgI0RvV2Q/k618MCQcsWVgbmI=";
  92.  
  93.     memset(Keys, 0, sizeof(unsigned short int) * 60);
  94.     memset(inversedKeys, 0, sizeof(unsigned short int) * 60);
  95.  
  96.     memcpy(Keys, str, strlen(str));
  97.  
  98.     inversedKeys[1] = modInverse(Keys[49], MOD);
  99.     inversedKeys[2] = - Keys[50];
  100.     inversedKeys[3] = - Keys[51];
  101.     inversedKeys[4] = modInverse(Keys[52], MOD);
  102.  
  103.     for (i = 5; i <= 52; i ++) {
  104.         inversedKeys[i] = Keys[52 - i];
  105.         inversedKeys[i + 1] = Keys[52 -i + 1];
  106.  
  107.         inversedKeys[i + 2] = modInverse(Keys[52 - i - 4], MOD);
  108.         inversedKeys[i + 3] = - Keys[52 - i - 2];
  109.         inversedKeys[i + 4] = - Keys[52 - i - 3];
  110.         inversedKeys[i + 5] = modInverse(Keys[52 - i - 1], MOD);
  111.     }
  112.  
  113.     str = &Keys;
  114.  
  115.     for (i = 0; i < sizeof(Keys); i ++) {
  116.             xil_printf("%c", str[i]);
  117.         }
  118.         xil_printf("\n");
  119.  
  120.     str = &inversedKeys;
  121.     for (i = 0; i < sizeof(inversedKeys); i ++) {
  122.         xil_printf("%c", str[i]);
  123.     }
  124.     xil_printf("\n");
  125.  
  126.     xil_printf("%d\n", modInverse(100, 7));
  127.  
  128.     cleanup_platform();
  129.     return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement