Advertisement
Guest User

neww

a guest
Sep 26th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 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.  
  54. char digits[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  55. int sbox1[] = {3,8,15,1,10,6,5,11,14,13,4,2,7,0,9,12};
  56. int sbox2[] = {15,12,2,7,9,0,5,10,1,11,14,8,6,13,3,4};
  57. int sbox3[] = {8, 6, 7, 9, 3, 12, 10, 15, 13, 1, 14, 4, 0, 11, 5, 2};
  58. int sbox4[] = {0, 15, 11, 8, 12, 9, 6, 3, 13, 1, 2, 4, 10, 7, 5, 14};
  59. int sbox5[] = {1, 15, 8, 3, 12, 0, 11, 6, 2, 5, 4, 10, 9, 14, 7, 13};
  60. int sbox6[] = {15, 5, 2, 11, 4, 10, 9, 12, 0, 3, 14, 8, 13, 6, 7, 1};
  61. int sbox7[] = {7, 2, 12, 5, 8, 4, 6, 11, 14, 9, 1, 15, 13, 3, 10, 0};
  62. int sbox8[] = {1, 13, 15, 0, 14, 8, 2, 11, 7, 4, 12, 10, 9, 3, 5, 6};
  63. char command[174];//Can be any size
  64. int i,count=0, result;
  65. int j=0,k;
  66. int matric_no;
  67. int id;
  68.  
  69.  
  70. void lab2(k)
  71. {
  72. switch(k)
  73. {
  74. case 1:
  75. for(i=0;i < 174; i++)
  76. {
  77.  
  78. command[i] = getchar();
  79. while(j<16)
  80. {
  81. if(digits[j]==command[i])
  82. {
  83. //printf("%c",digits[j]);
  84.  
  85. break;
  86. }
  87. else
  88. {
  89. j++;
  90. }
  91. count=count+1;
  92.  
  93. }
  94. printf("%d", sbox1[count]);
  95. j=0;
  96. count=0;
  97. }
  98. break;
  99.  
  100. case 2:
  101. for(i=0;i < 174; i++)
  102. {
  103.  
  104. command[i] = getchar();
  105. while(j<16)
  106. {
  107. if(digits[j]==command[i])
  108. {
  109. //printf("%c",digits[j]);
  110.  
  111. break;
  112. }
  113. else
  114. {
  115. j++;
  116. }
  117. count=count+1;
  118.  
  119. }
  120. printf("%d", sbox2[count]);
  121. j=0;
  122. count=0;
  123. }
  124. break;
  125. case 3:
  126. for(i=0;i < 174; i++)
  127. {
  128.  
  129. command[i] = getchar();
  130. while(j<16)
  131. {
  132. if(digits[j]==command[i])
  133. {
  134. //printf("%c",digits[j]);
  135.  
  136. break;
  137. }
  138. else
  139. {
  140. j++;
  141. }
  142. count=count+1;
  143.  
  144. }
  145. printf("%d", sbox1[count]);
  146. j=0;
  147. count=0;
  148. }
  149. break;
  150. case 4:
  151. for(i=0;i < 174; i++)
  152. {
  153.  
  154. command[i] = getchar();
  155. while(j<16)
  156. {
  157. if(digits[j]==command[i])
  158. {
  159. //printf("%c",digits[j]);
  160.  
  161. break;
  162. }
  163. else
  164. {
  165. j++;
  166. }
  167. count=count+1;
  168.  
  169. }
  170. printf("%d", sbox1[count]);
  171. j=0;
  172. count=0;
  173. }
  174. break;
  175. case 5:
  176. for(i=0;i < 174; i++)
  177. {
  178.  
  179. command[i] = getchar();
  180. while(j<16)
  181. {
  182. if(digits[j]==command[i])
  183. {
  184. //printf("%c",digits[j]);
  185.  
  186. break;
  187. }
  188. else
  189. {
  190. j++;
  191. }
  192. count=count+1;
  193.  
  194. }
  195. printf("%d", sbox1[count]);
  196. j=0;
  197. count=0;
  198. }
  199. break;
  200. case 6:
  201. for(i=0;i < 174; i++)
  202. {
  203.  
  204. command[i] = getchar();
  205. while(j<16)
  206. {
  207. if(digits[j]==command[i])
  208. {
  209. //printf("%c",digits[j]);
  210.  
  211. break;
  212. }
  213. else
  214. {
  215. j++;
  216. }
  217. count=count+1;
  218.  
  219. }
  220. printf("%d", sbox1[count]);
  221. j=0;
  222. count=0;
  223. }
  224. break;
  225. case 7:
  226. for(i=0;i < 174; i++)
  227. {
  228.  
  229. command[i] = getchar();
  230. while(j<16)
  231. {
  232. if(digits[j]==command[i])
  233. {
  234. //printf("%c",digits[j]);
  235.  
  236. break;
  237. }
  238. else
  239. {
  240. j++;
  241. }
  242. count=count+1;
  243.  
  244. }
  245. printf("%d", sbox1[count]);
  246. j=0;
  247. count=0;
  248. }
  249. break;
  250. case 8:
  251. for(i=0;i < 174; i++)
  252. {
  253.  
  254. command[i] = getchar();
  255. while(j<16)
  256. {
  257. if(digits[j]==command[i])
  258. {
  259. //printf("%c",digits[j]);
  260.  
  261. break;
  262. }
  263. else
  264. {
  265. j++;
  266. }
  267. count=count+1;
  268.  
  269. }
  270. printf("%d", sbox1[count]);
  271. j=0;
  272. count=0;
  273. }
  274. break;
  275.  
  276. }
  277. default:
  278. printf("invalid\n");
  279. printf("\n");
  280. }
  281.  
  282. int main()
  283. {
  284. init_platform();
  285.  
  286. matric_no = getchar();
  287. id=matric_no%8;
  288. lab2(id);
  289.  
  290. cleanup_platform();
  291. return 0;
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement