Chủ Nhật, 30 tháng 3, 2014

MÃ HÓA THÔNG ĐIỆP


  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <alloc.h>
  4. char *crypt(char *tdiep, int column)
  5. {
  6. char tam[255], *result;
  7. int i = 0, k = 0, n, j=0;
  8. while(tdiep[i] != 0)
  9. {
  10. if (isalnum(tdiep[i]))
  11. tam[k++] = tdiep[i];
  12. i++;
  13. }
  14. tam[k] = 0;
  15. result = (char *)malloc(k+1);
  16. for (i=0; i<column; i++)
  17. {
  18. = 0;
  19. while(n+< k)
  20. {
  21. result[j++] = tolower(tam[n+i]);
  22. += column;
  23. }
  24. }
  25. result[k] = 0;
  26. return result;
  27. }
  28. void main()
  29. {
  30. char thongdiep[255], *mahoa;
  31. int col;
  32. printf("\nNhap thong diep can ma hoa : ");
  33. gets(thongdiep);
  34. printf("\nCho biet so cot : ");
  35. scanf("%d", &col);
  36. mahoa = crypt(thongdiep, col);
  37. printf("\nThong diep da duoc ma hoa thanh : %s", mahoa);
  38. getch();
  39. }

0 nhận xét:

Đăng nhận xét