IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

au lieu de prendre la valeur d'apres scanf on prendre valeur d'apres une liste ou tableau


Sujet :

C

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut au lieu de prendre la valeur d'apres scanf on prendre valeur d'apres une liste ou tableau
    salut
    je veux modifier la fonction
    telque la valeur demande par printf sera prendre d'apres une tableau ou liste .chaque instanciation de la focntion on choisit une valeur de liste ou tableau des entiers premiers comme
    a:{23, 29, 31, 37, 41, 43, 47,53, 59, 61, 67, 71, 73, 79, 83 ,89 ,97, 101, 103, 107, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521,653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857 }
    b*:{109 ,113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337,401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929}

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    void Rsa::p_e_e(void)
     
    {
     
    	int a,b,*reste,*s,*q;
     
       reste=(int*)malloc(sizeof(int));  //initialisation de reste
     
       s=(int*)malloc(sizeof(int));  //initialisation de s
     
       q=(int*)malloc(sizeof(int));  //initialisation de q
     
       printf("\n\n\t\t\t   ********************\n");
     
       printf("\t\t\t   *PREMIERS ENTRE EUX*\n");
     
    	printf("\t\t\t   ********************\n\n\n");
     
       printf("Donner le 1er entier : ");
     
       scanf("%d",&a);
     
       printf("\nDonner le 2eme entier : ");
     
       scanf("%d",&b);
     
     
       *s=a;
     
       *q=b;
     
       *reste=fmod(*s,*q);
     
       while(*reste!=0 && *reste>0)
     
       {
     
       	*s=*q;
     
          *q=*reste;
     
          *reste=fmod(*s,*q);
     
       }
     
     
     
       if(*q==1)
     
       {
       printf("\n\n%d et %d sont premiers entre eux.",a,b);
     
       }
       else
     
       {
       	printf("\n\n%d et %d ne sont pas premiers entre eux.",a,b);
     
       }
       getch();
     
    }

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Canada

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 116
    Points : 32 968
    Points
    32 968
    Billets dans le blog
    4
    Par défaut
    Bonsoir,

    ton utilisation des malloc est inutile en plus d'être mauvaise et entrainer une fuite mémoire.

    Je ne vois pas trop où se situe ton problème.
    Ne sais-tu pas prendre un élément d'un tableau ? Avec un index peut-être ?
    Btw, il s'agit de C et non de C++, je déplace.
    Pensez à consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation réseau ?
    Aucune aide via MP ne sera dispensée. Merci d'utiliser les forums prévus à cet effet.

  3. #3
    Membre expert
    Avatar de kwariz
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Octobre 2011
    Messages
    898
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2011
    Messages : 898
    Points : 3 352
    Points
    3 352
    Par défaut
    Bonjour,

    Bon avec le namespace et le cast du malloc ça sent le C++ quand même un peu

    Mais sinon je ne comprends pas trop la question, les deux listes que tu proposes sont des listes de nombres premiers (si je ne me trompe pas). Forcément quels que soient les nombres choisis ta fonction va imprimer qu'ils sont premiers entre eux ...

  4. #4
    Membre confirmé Avatar de saad.hessane
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    315
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 315
    Points : 496
    Points
    496
    Par défaut
    Bonjour,

    Je ne te cache pas que je n'ai pas très bien compris la question. Néanmoins je vais essayer de t'expliquer le code que tu as mis en espérant que ta prochaine question soit un peu plus clair.

    Avant d'écrire un code, on essaye d'abord de se poser la question "quoi?". Qu'est ce qu'on attend du programme? Dans ton cas tu veux savoir si deux nombres a et b sont premier entre eux.
    Ensuite vient la question "comment?". Les mathématiciens d'une autre époque, en l’occurrence Euclide nous répond que a et b sont premier entre eux si pgcd(a,b) = 1 .
    La question maintenant est "comment calculer pgcd(a,b) ?".
    Toujours avec Euclide, il nous répond :
    Il s'agit de divisions en cascade: les résultats de l'une servent à poser la suivante:
    • Le diviseur B devient le dividende; et
    • Le reste r1 devient le diviseur.
    • Arrêt lorsque le reste de la division est nul.
    • Le reste trouvé avant le reste nul est le PGCD.

    Maintenant qu'on sait ce qu'on attend du programme, je regarde ton code :
    • Comme dit Bousk, les malloc sont inutiles. (Essaye de relire la partie de ton cours qui dit quand il faut utiliser un malloc).
    • Pourquoi utilises-tu fmod? Tu travailles sur des entiers, tu as un opérateur pour faire le modulo (%).
    • Si "reste" est strictement supérieur à zéro, alors il est forcément différent de 0.
    • Il est interdit de diviser par 0, comme il est interdit de faire modulo 0. Prévoir un test sur b.

    Une fois n'est pas coutume, une solution :
    Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
     
    #include <cstdio>
     
    void Rsa::p_e_e(void)
    {
      int a,b,reste,s,q;
     
      printf("\n\n");
      printf("\t\t\t   ********************\n");
      printf("\t\t\t   *PREMIERS ENTRE EUX*\n");
      printf("\t\t\t   ********************\n");
      printf("\n\n");
     
      //Entrée utilisateur
      printf("Donner le 1er entier : ");
      scanf("%d",&a);
     
      printf("\nDonner le 2eme entier : ");
      scanf("%d",&b);
     
      if(b==0)
      {
        //printf Message d'erreur
        return;
      }
     
      //Calcule du PGCD
      s=a;
      q=b;
      reste=s%q;
     
      while(reste>0)
      {
        s=q;
        q=reste;
        reste=s%q;
      }
     
      //Affichage du résultat
      if(q==1)
      {
        printf("\n\n%d et %d sont premiers entre eux.",a,b);
      }
      else
      {
        printf("\n\n%d et %d ne sont pas premiers entre eux.",a,b);
      }
    }

  5. #5
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut
    bonjour
    j'essaie de modifier la code RSA de cryptage selon mon besoin et le code precedement ,ce ne pas que je le fais ,ce code de rsa telechargé d'apres internet.mais je fais de changement pour que soit adaptable a mon besoin
    mon question est : au lieu que la fonction demande au utilisateur de taper un nombre premiers,je ferais un methode qui prend la valeur d'apres une tableau ou liste defini en interieru de methode (a,b).donc ,puisque j'ai un tableau de nombre premier ,je ne besoin pas puis au teste de pgcd ou autre chose
    ce ça mon but ,j'espere que je calrifier mon question et le probleme

  6. #6
    Membre confirmé Avatar de saad.hessane
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    315
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 315
    Points : 496
    Points
    496
    Par défaut
    Citation Envoyé par chirazch Voir le message
    j'espere que je calrifier mon question et le probleme
    Non, pas trop désoler.
    Tu as télécharger un code à partir d'internet (ça j'avais compris). Ce code que tu as téléchargé demande à l'utilisateur d'entrer un couple de nombre (a,b), et vérifie si les deux nombres sont premiers entre eux.
    Les étapes de RSA sont :

    • Choisir p et q deux nombres premiers (très grands en pratique).
    • Choisir e un nombre premier avec (p-1)(q-1).
    • Trouver d tel que (e*d) équivaut à 1 modulo (p-1)(q-1).

    Les tableaux des nombres que tu donnes sont premiers (première étape de l'algorithme). Le programme que tu as téléchargé d'internet vérifie que deux nombres sont premiers entre eux (deuxième étape de l'algorithme).

    Que veux-tu faire exactement?
    Essaye d'être le plus claire possible, avec des phrases courtes si possible

  7. #7
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut
    salut
    je veux changer tous les code de RSA ,il n'est pas compatible a mes besoin.
    car j'ai travaille sous ns3,
    je veux appeller au une fichier .cc
    les methodes de rsa :cryptage,decryptage,cle publique et clé prive.
    quand je fais l'appeler au methode cryptage je veux seulement entre une seule parametre qui est une donné de type string
    puis je veux apres decrypter quand j'entre au le fonction une message crypté.
    mais d'apres le code que j'ai ;il ne permis pas d efaire ça
    c'est pour cela j'essaie de le changer tous mais etape par etape
    mais j'ai trouves quelque conflit puisque je suis debutant au langage c
    ce ça le code que chez moi ;tous d'abord c'st un ficheir .c puis je le divisé en deux partie l'un . h et l'autre .cc

    Rsa.cc
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    1271
    1272
    1273
    1274
    1275
    1276
    1277
    1278
    1279
    1280
    1281
    1282
    1283
    1284
    1285
    1286
    1287
    1288
    1289
    1290
    1291
    1292
    1293
    1294
    1295
    1296
    1297
    1298
    1299
    1300
    1301
    1302
    1303
    1304
    1305
    1306
    1307
    1308
    1309
    1310
    1311
    1312
    1313
    1314
    1315
    1316
    1317
    1318
    1319
    1320
    1321
    1322
    1323
    1324
    1325
    1326
    1327
    1328
    1329
    1330
    1331
    1332
    1333
    1334
    1335
    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    1354
    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    1369
    1370
    1371
    1372
    1373
    1374
    1375
    1376
    1377
    1378
    1379
    1380
    #include <conio.h>
    #include <stdio.h>
    #include <string.h>
    #include <alloc.h>
    #include <math.h>
    #include <time.h>
    #include <stdlib.h>
    #include <Rsa.h>
    using namespace std;
    using namespace ns3;
     
    namespace ns3
    {
     
    //******************************** a partir de SHA_1  *********************************
     
     
     
    typedef unsigned char *POINTER;/* POINTER defines a generic pointer type */
     
     
    typedef unsigned long int UINT4;/* UINT4 defines a four byte word */
     
    typedef unsigned char BYTE; /* BYTE defines a unsigned character */
     
    // ************* Entrées *******************
    unsigned char message[10] = {'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'a', 'b' };
     
    unsigned char digest[20];
    char *dig1 = "A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D";
    char *dig2 = "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1";
    char *dig3 = "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F";
    unsigned char *mess56 = 
    	"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
     
     
     
    //************************Fin de SHA_1**********************************************************//
    /* endian.c */
     
    void Rsa::endianTest(int *endian_ness)
    {
    	if((*(unsigned short *) ("#S") >> 8) == '#')
    	{
    		/* printf("Big endian = no change\n"); */
    		*endian_ness = !(0);
    	}
    	else
    	{
    		/* printf("Little endian = swap\n"); */
    		*endian_ness = 0;
    	}
    }
    //***********************Debut fonctions de hachage ***************************
    void Rsa::SHAInit(SHA_CTX *shsInfo)
    {
        endianTest(&shsInfo->Endianness);
        /* Set the h-vars to their initial values */
        shsInfo->digest[ 0 ] = h0init;
        shsInfo->digest[ 1 ] = h1init;
        shsInfo->digest[ 2 ] = h2init;
        shsInfo->digest[ 3 ] = h3init;
        shsInfo->digest[ 4 ] = h4init;
     
        /* Initialise bit count */
        shsInfo->countLo = shsInfo->countHi = 0;
    }
    /*************************** Fonctions hachages*********************************/
    FILE *interm;
     
    void Rsa::hachage()
    {
    	SHA_CTX sha;
    	int i;
    	BYTE big[1000];
     
    	SHAInit(&sha);
    	SHAUpdate(&sha, message, 3);
    	SHAFinal(digest, &sha);
     
    	for (i = 0; i < 20; i++)
    	{
    		if ((i % 4) == 0) printf(" ");
    		printf("%02x", digest[i]);
    	}
     
    	interm=fopen("interm.txt" , "wb");
    	if(interm==NULL)
    	{
       	printf("Impossible d'ouvrir le fichier resultat.\n");
       }
    	  fwrite(&digest,20*sizeof(unsigned  char),1,interm);
    	  fclose(interm);
    	return 0;
    }
     
    /***************************MENU hachage*************************************/
     
    void Rsa::menu_hachage()
    {
     
     
       printf("\t\t\t     *MENU hachage*\n"); 
      hachage();
     
    }
    /*************************************************/
    unsigned long int n,e;
    void Rsa::initCle()
    {
     
    	printf("\n\n\n\tdonner votre cle publique n : ");
    	//printf("le nom du fichier %s\n", nom_fichier); 
     
       scanf("%d",&n);
       printf("\n\n\n\tdonner votre cle publique e : ");
       scanf("%d",&e);
     
    }
    /***********************************algocomplet*******************/
    FILE *msg, *msg1, *interm1;
    void Rsa::algoComplet( )
    {
    	clock_t t1, t2;
     
    	t1 = clock();
    	//initCle();
    	hachage();
    initCle();
    interm1=fopen("interm1.cry" , "wb");
    	if(interm1==NULL)
    	{
       	printf("Impossible d'ouvrir le fichier resultat.\n");
       }
    	interm=fopen("interm.txt" , "rb");
    	if(interm==NULL)
    	{
       	printf("Impossible d'ouvrir le fichier resultat.\n");
       }
    //crypter();
     
    msg=fopen("message.txt" , "w");
    fwrite(&message,10*sizeof(unsigned  char),1,msg);
    fclose(msg);
    msg=fopen("message.txt" , "r");
    msg1=fopen("message.cry" , "wb");
    	if(msg1==NULL)
    	{
       	printf("Impossible d'ouvrir le fichier resultat.\n");
       }
    crypter();
    fclose(interm);
    	fclose(interm1);
    		fclose(msg);
    	fclose(msg1);
    t2 = clock();
    	printf("\n\n\n\n\n\n\n\n\n\nLe cryptage de votre fichier est termine.");
       printf("\n\nvotre fichier crypter se nomme result.cry");
       printf("\n\n\n\n\n\n\n\n\n\nLe temps de calcul = %f\n", (float)(t2-t1)/CLOCKS_PER_SEC);
       system("PAUSE");
    	getch();
     
    }
    /***************************MENU CRYPTOGRAPHIE*********************************/
     
    /*******************************CRYPTER****************************************/
     void Rsa:: crypter()
    {
            unsigned char c;
    	unsigned long int i=0;
    	unsigned long int k;
    	char nom_fichier[20];
    printf("\n\n\t\t\t   	*********\n");
       printf("\t\t\t     	*CRYPTER*\n");
    printf("\t\t\t     	*********\n\n\n\n");
       fflush(stdin);
     
       //clrscr();
       printf("\n\n\t\tATTENDEZ SVP PENDANT LE CRYPTAGE.");
    	while((feof(interm)==0) && (fread(&c,sizeof(unsigned char),1,interm)!=0))
     
      	{
    		printf("le caractère est %c\n", c);
      	   fseek(interm,sizeof(unsigned char)*i,SEEK_SET);
         	fread(&c,sizeof(unsigned char),1,interm);//interm:le fichier qui contient les données sources claires
       	k=crypt(c,n,e);
      fwrite(&k,sizeof(unsigned long int),1,interm1);// interm1: le fichier qui contient les données chiffres
    	i=i+1;
       }
    	i = 0;
    printf("\n\n\t\tATTENDEZ SVP PENDANT LE CRYPTAGE.");
    	while((feof(msg)==0) && (fread(&c,sizeof(unsigned char),1,msg)!=0))
     
      	{
    		printf("le caractère est %c\n", c);
      	   fseek(msg,sizeof(unsigned char)*i,SEEK_SET);
         	fread(&c,sizeof(unsigned char),1,msg);
       	k=crypt(c,n,e);
      fwrite(&k,sizeof(unsigned long int),1,msg1);
    	i=i+1;
       }
     
    }
     
    /******************************FONCTION CRYPTAGE*******************************///******************************
    unsigned long int Rsa:: crypt(unsigned char k,unsigned long int n,unsigned long int e)
    {
    	unsigned long int i,res=1,nbre;
    	nbre=((unsigned long int)k);
    	for(i=0;i<e;i++)
    	{
        	res = res * nbre;
    	 	res = fmod(res,n);
    	}
    	return res;
    }
     
    /*******************************DECRYPTER**************************************/
    void Rsa:: decrypter(void)
    {
    FILE *source;
     
       FILE *res_decrypt;
    	char l;
       unsigned long int h=0;
    	unsigned long int d,n;
       unsigned long int lect_int;
    	char nom_fichier[20],nom_fin[20];
       printf("\n\n\t\t\t   	***********\n");
       printf("\t\t\t     	*DECRYPTER*\n");
    	printf("\t\t\t        ***********\n\n\n\n");
       fflush(stdin);
    	printf("Donner le nom du fichier avec son extension : ");
    	gets(nom_fichier);
    	printf("Donner le nom du fichier de destination avec son extension : ");
    	gets(nom_fin);
    	printf("\n\n\n\tdonner votre cle prive n : ");
       scanf("%d",&n);
       printf("\n\n\n\tdonner votre cle prive d : ");
       scanf("%d",&d);
    	source=fopen(nom_fichier , "rb");
    	if(source==NULL)
     
    	{
     
       	printf("Impossible d'ouvrir le fichier a decrypter.\n");
     
          erreur();
       }
    	res_decrypt=fopen(nom_fin , "wb");
    	if(res_decrypt==NULL)
     
    	{
       	printf("Impossible d'ouvrir le fichier resultat.\n");
          erreur();
       }
       //clrscr();
       printf("\n\n\t\tATTENDEZ SVP PENDANT LE DECRYPTAGE.");
    	while((feof(source)==0) && (fread(&lect_int,sizeof(unsigned long int),1,source)!=0))
    	{
    	   fseek(source,sizeof(unsigned long int)*h,SEEK_SET);
          fread(&lect_int,sizeof(unsigned long int),1,source);
          l=decrypt(lect_int,d,n);
          fwrite(&l,sizeof(unsigned char),1,res_decrypt);
          h=h+1;
       }
    	fclose(source);
    	fclose(res_decrypt);
    	printf("\n\n\n\n\n\n\n\n\n\nLe decryptage de votre fichier est termine.");
       getch();
    }
     
    /****************************FONCTION DECRYPTAGE*******************************/
     
    unsigned char Rsa::decrypt(unsigned long int k,unsigned long int d,unsigned long int n)
     
    {       unsigned long int i,res=1;
    	unsigned char x;
    	for(i=0;i<d;i++)
    	{
        	res=res*k;
          res=fmod(res,n);
    	}
    	x=((unsigned char)res);
    	return x;
     
    }
     
    /********************************LECTURE***************************************/
     
    void Rsa::lecture(void)
     
    {
    	int compteur_car;
       int compteur_ligne;
       int car_lect;
       FILE *fichier;
       char nom_fichier[20];
       printf("\n\n\t\t\t**********************\n");
       printf("\t\t\t*LECTURE D'UN FICHIER*\n");
    	printf("\t\t\t**********************\n\n\n");
     fflush(stdin);
     
       printf("Donner le nom du fichier a lire (avec son extension) : ");
       gets(nom_fichier);
       fichier=fopen(nom_fichier,"r");
       if(fichier==NULL)
       {
       	printf("\n\nImpossible d'ouvrir le fichier a lire.\n");
       }
       compteur_ligne=0;
       compteur_car=0;
    if(fichier!=NULL){
       printf("\n\nLecture du fichier en cours.\n\n");
       while((car_lect = fgetc(fichier))!=EOF)
       {
       	compteur_car = compteur_car + 1;
          printf("%c",car_lect);
          if(compteur_car == 40)
          {
          	compteur_car = 0;
             compteur_ligne = compteur_ligne + 1;
          }
          if(compteur_ligne>=17)
          {
          	compteur_car = 0;
             compteur_ligne = 0;
             getch();
     
             //clrscr();
          }
       }
       printf("\n\n\nLa lecture du fichier est terminee.");
       }
       fclose(fichier);
       getch();
    }
    /*******************************COMPARAISON************************************/
     
    void Rsa::comparer(void)
    {
    	int compt=0;
       int car_lect,car_lect2;
       FILE *fichier;
       FILE *fichier2;
       char nom_fichier[20];
       char nom_fichier2[20];
       printf("\n\n\t\t\t  ***************************\n");
       printf("\t\t\t  *COMPARAISON DE 2 FICHIERS*\n");
    	printf("\t\t\t  ***************************\n\n\n");
     
       fflush(stdin);
       printf("Donner le nom du fichier source (avec son extension) : ");
       gets(nom_fichier);
       printf("Donner le nom du fichier a comparer (avec son extension) : ");
     
       gets(nom_fichier2);
       fichier=fopen(nom_fichier,"r");
       fichier2=fopen(nom_fichier2,"r");
       if(fichier==NULL)
     
       {
       	printf("\n\nImpossible d'ouvrir le fichier source.\n");
     
       }
     
       if(fichier2==NULL)
     
       {
       	printf("\n\nImpossible d'ouvrir le fichier a comparer.\n");
       }
    if((fichier!=NULL) && (fichier2!=NULL))
    	{
       printf("\n\nLecture des fichiers en cours.\n\n");
       while(((car_lect = fgetc(fichier))!=EOF)&&((car_lect2 = fgetc(fichier2))!=EOF))
       {
       	if(car_lect!=car_lect2)
      	{
             compt=compt+1;
          }
     
       }
     
       if(compt==0)
    	{
          printf("\n\nLes deux fichiers sont identiques.");
     
       }
       else
    	{
          printf("\n\nIl y a %d caracteres d'ecart.",compt);
       }
       }
       fclose(fichier);
       fclose(fichier2);
      	getch();
    }
    /******************************CHOIX CRYPTO************************************/
    void Rsa::choix_crypto(void)
    {
    	int choix;
       printf("\n\n\n\n\t   QUE SOUHAITEZ VOUS FAIRE ?\n\n\n\n\n");
       printf("\t   TAPEZ :\n\n\n");
       printf("\t\t1\t   POUR\t        REVENIR AU MENU PRINCIPAL\n\n");
       printf("\t\t2\t   POUR\t        REVENIR AU MENU CRYPTOGRAPHIE\n\n");
       printf("\t\t3\t   POUR\t        QUITTER LE LOGICIEL\n\n\n");
       printf("\t   CHOIX : ");
       scanf("%d",&choix);
     
     
     
       switch(choix)
     
       {
       	case 1 : //clrscr();
          			menu();
          break;
          case 2 : //clrscr();
          			menu_crypto();
          break;
          case 3 : quitter();
          break;
          default : erreur();
       }
    }
    /******************************MENU CALCUL*************************************/
    void Rsa::menu_calcul(void)
    {
     	int choix=0;
     	printf("\n\t\t\t     *************\n");
       printf("\t\t\t     *MENU CALCUL*\n");
    	printf("\t\t\t     *************\n\n\n");
       printf("\t   TAPEZ :\n\n\n\n");
       printf("\t\t1\t   POUR\t       CALCULER LE PGCD DE 2 NOMBRES\n\n");
       printf("\t\t2\t   POUR\t       DECOMPOSER UN NOMBRE EN NOMBRES PREMIERS\n\n");
       printf("\t\t3\t   POUR\t       CALCULER UN MODULO\n\n");
     
       printf("\t\t4\t   POUR\t       TESTER LA PRIMARITE D'UN NOMBRE\n\n");
       printf("\t\t5\t   POUR\t       VOIR SI 2 NOMBRES SONT PREMIERS ENTRE EUX\n");
       printf("\t\t6\t   POUR\t       MENU PRECEDENT\n\n\n");
       printf("\t   CHOIX : ");
       scanf("%d",&choix);
       switch(choix)
       {
       	case 1 : //clrscr();
          			pgcd();
                   //clrscr();
                   choix_calcul();
          break;
          case 2 : //clrscr();
          			decomposition();
     
                   //clrscr();
     
                   choix_calcul();
     
          break;
          case 3 : //clrscr();
     
        		modulo();
                   //clrscr();
                   choix_calcul();
          break;
     
          case 4 : //clrscr();
          			primarite();
     
                   //clrscr();
                   choix_calcul();
          break;
          case 5 : //clrscr();
          			p_e_e();
     
                   //clrscr();
                   choix_calcul();
          break;
          case 6 : //clrscr();
          menu();
          break;
          default : erreur();
     
       }
    }
    /*********************************CALCUL DU PGCD*******************************/
    void Rsa::pgcd(void)
    {
    	int a,b,*reste,*s,*q;
       reste=(int*)malloc(sizeof(int));  //initialisation de reste
       s=(int*)malloc(sizeof(int));  //initialisation de s
       q=(int*)malloc(sizeof(int));  //initialisation de q
     
     
       printf("\n\n\t\t\t     ****************\n");
       printf("\t\t\t     *CALCUL DU PGCD*\n");
    	printf("\t\t\t     ****************\n\n\n");
       printf("Donner le 1er entier : ");
       scanf("%d",&a);
       printf("\nDonner le 2eme entier : ");
       scanf("%d",&b);
       *s=a;
       *q=b;
       *reste=fmod(*s,*q);
       while(*reste!=0 && *reste>0)
       {
       	*s=*q;
          *q=*reste;
          *reste=fmod(*s,*q);
       }
       printf("\nle PGCD de %d et %d est %d.",a,b,*q);
       getch();
    }
    /*********************************MODULO***************************************/
    void Rsa::modulo(void)
    {
       int res,x,y;
     
       printf("\n\n\t\t\t    ******************\n");
     
       printf("\t\t\t    *CALCUL DU MODULO*\n");
     
    printf("\t\t\t    ******************\n\n\n");
     
       printf("\n\ncalcul de X modulo Y");
     
       printf("\n\nDonner X : ");
     
       scanf("%d",&x);
     
       printf("\n\nDonner Y : ");
     
       scanf("%d",&y);
       res=fmod(x,y);
       printf("\n\n%d modulo %d est egal a %d.",x,y,res);
       getch();
     
    }
    /*******************************PRIMARITE**************************************/
    void Rsa::primarite(void)
     
    {
    	int x,i,taille=0;
     
       printf("\n\n\t\t\t***********************\n");
     
       printf("\t\t\t*PRIMARITE D'UN NOMBRE*\n");
     
    	printf("\t\t\t***********************\n\n\n");
     
       fflush(stdin);
     
       printf("Donner un entier : ");
     
       scanf("%d",&x);
       if(x==0 || x==1)
     
       {
     
       	printf("%d n'est pas premier.",x);
     
       }
     
     
       else
     
       {
     
       	for(i=2;i<x;i++)
     
       	{
     
          	if(x%i==0)
     
          	{
     
             	taille=taille+1;
     
          	}
     
       	}
     
     
     
       	if(taille==0)
     
       	{
     
       		printf("%d est premier.",x);
     
       	}
     
       	else
     
       	{
     
       		printf("%d n'est pas premier.",x);
     
       	}
     
       }
    	getch();
     
    }
     
    /**************************PREMIERS ENTRE EUX**********************************/
    void Rsa::p_e_e(void)
     
    {
     
    	int a,b,*reste,*s,*q;
     
       reste=(int*)malloc(sizeof(int));  //initialisation de reste
     
       s=(int*)malloc(sizeof(int));  //initialisation de s
     
       q=(int*)malloc(sizeof(int));  //initialisation de q
     
       printf("\n\n\t\t\t   ********************\n");
     
       printf("\t\t\t   *PREMIERS ENTRE EUX*\n");
     
    	printf("\t\t\t   ********************\n\n\n");
     
       printf("Donner le 1er entier : ");
     
       scanf("%d",&a);
     
       printf("\nDonner le 2eme entier : ");
     
       scanf("%d",&b);
     
     
       *s=a;
     
       *q=b;
     
       *reste=fmod(*s,*q);
     
       while(*reste!=0 && *reste>0)
     
       {
     
       	*s=*q;
     
          *q=*reste;
     
          *reste=fmod(*s,*q);
     
       }
     
     
     
       if(*q==1)
     
       {
       printf("\n\n%d et %d sont premiers entre eux.",a,b);
     
       }
       else
     
       {
       	printf("\n\n%d et %d ne sont pas premiers entre eux.",a,b);
     
       }
       getch();
     
    }
    /****************************CHOIX CALCUL**************************************/
     
    void Rsa::choix_calcul(void)
     
    {
     
    	int choix;
       printf("\n\n\n\n\t   QUE SOUHAITEZ VOUS FAIRE ?\n\n\n\n\n");
     
       printf("\t   TAPEZ :\n\n\n");
     
       printf("\t\t1\t   POUR\t        REVENIR AU MENU PRINCIPAL\n\n");
     
       printf("\t\t2\t   POUR\t        REVENIR AU MENU DES CALCULS\n\n");
     
       printf("\t\t3\t   POUR\t        QUITTER LE LOGICIEL\n\n\n");
     
       printf("\t   CHOIX : ");
     
       scanf("%d",&choix);
       switch(choix)
     
       {
     
       	case 1 : //clrscr();
     
          			menu();
     
          break;
     
     
     
          case 2 : //clrscr();
     
          			menu_calcul();
     
          break;
          case 3 : quitter();
     
          break;
     
          default : erreur();
     
       }
     
    }
     
     
     
    /********************************ERREUR****************************************/
    void Rsa::erreur(void)
     
    {
     
    	int choix;
     
    	printf("\nERREUR DE SAISIE.");
     
          getch();
     
       //clrscr();
     
       printf("\n\n\n\n\t\tSOUHAITEZ VOUS REVENIR AU MENU PRINCIPAL ?\n\n\n\n\n");
     
       printf("\t   TAPEZ :\n\n\n");
     
       printf("\t\t1\t   POUR\t        REVENIR AU MENU PRINCIPAL\n\n");
     
       printf("\t\t2\t   POUR\t        QUITTER LE LOGICIEL\n\n\n");
     
       printf("\t   CHOIX : ");
     
       scanf("%d",&choix);
     
     
     
       switch(choix)
     
       {
     
       	case 1 : //clrscr();
     
          			menu();
     
          break;
     
     
     
          case 2 : quitter();
     
          break;
     
     
     
          default : erreur();
     
     
       }
     
    }
    /***********************************inscription********************************/
     void Rsa::inscri(void)
    {
     
       int p,q,e,z,d,n;
     
       //clrscr();
     
          printf("\n\n\t\t\t\t*************\n");
     
       printf("\t\t\t\t*INSCRIPTION*\n");
     
    	printf("\t\t\t\t*************\n\n\n");
     
     
     
    	pq(&p,&q);
     
       n=p*q;
     
       z=(p-1)*(q-1);
     
       e=p_e_e2(z);
     
       printf("\n\n\n\n\n\n\n\n\t( n : %d ; e : %d ) est votre cle publique.",n,e);
     
       d=cle_priv(e,z);
     
       printf("\n\n\n\n\t( n : %d ; d : %d ) est votre cle privee.",n,d);
     
       getch();
     
       getch();
     
       getch();
     
       //clrscr();
     
       choix_crypto();
     
     
     
    }
     
     
    /******************************************************************************/
    int Rsa::p_e_e2(int x)
     
    {
     
    	int y,*tab[100000],*taille,rep,i;
     
       taille=(int*)malloc(sizeof(int));
     
       *taille=0;
     
       for(i=0;i<100000;i++)
     
       {
     
       	tab[i]=(int*)malloc(sizeof(int));
     
       }
     
     
     
       for(y=1;y<x;y++)
       {
     
       	pgcd2(x,y,taille,tab);
     
       }
     
       //randomize();
     
    	rep=*tab[rand()%*taille];
     
       return rep;
     
    }
     
    /******************************************************************************/
    void Rsa::pgcd2(int a,int b,int* taille,int* tab[])
    {
     
    int *reste,*k,*s,*q;
     
    reste=(int*)malloc(sizeof(int));
     
    k=(int*)malloc(sizeof(int));
     
    s=(int*)malloc(sizeof(int));
     
    q=(int*)malloc(sizeof(int));
     
    *s=a;
     
    *q=b;
     
    *reste=1;
     
    decomp(s,q,reste,k);
     
    while(*reste!=0&&*reste>0)
     
                   {
     
                   *s=*q;
     
                   *q=*reste;
     
                   decomp(s,q,reste,k);
     
                   }
     
    if(*q==1)
     
    {
     
       *tab[*taille]=b;
     
       *taille=*taille+1;
     
    }
     
    }
    /******************************************************************************/
     
    void Rsa::decomp(int*s,int*q,int*r,int*k)
     
    {
    *k=0;
     
    while(*s>=*q)
     
               {
     
               *s=*s-*q;
     
               *k=*k+1;
     
               }
     
    *r=*s;
     
    }
     
     
     
    /******************************************************************************/
     
    int Rsa::cle_priv(int e,int z)
     
    {
     
    	int d,i=0;
     
       while((e*i)%z!=1)
     
       {
     
       	i=i+1;
     
       }
     
       d=i;
     
       return d;
     
    }
     
    /******************************************************************************/
     
    void Rsa::pq(int* p,int* q)
     
    {
     
    int t[200],i,y,j,taille=0;
     
       for (i=3;i<200;i++)
     
       			{ y=0;
     
                 for(j=2;j<i;j++)
     
                 			{
     
                         if(i%j==0)
     
                         			{
     
                                  y=y+1;
     
                                  }
     
                         }
     
                 if(y==0)
                 	{
                      //printf("   %d   ",i);
     
                         t[taille]= i;
     
                         taille=taille+1;
                   }
                }
     
    //randomize();
     
    *p=t[rand()%taille];
     
    *q=t[rand()%taille];
    }
     
     
    /*************************DECOMPOSITION****************************************/
     
     
     
    void Rsa::decomposition(void)
     
    {
     
    	int prem[100000],puissance[100000];
     
    	int n,o,i,j,k,compt,taille=0;
     
     
     
       printf("\n\n\t\t     ***********************************\n");
     
       printf("\t\t     *DECOMPOSITION EN NOMBRES PREMIERS*\n");
     
    	printf("\t\t     ***********************************\n\n\n");
     
     
     
       printf("\nDonner 1 entier : ");
     
    	scanf("%d",&n);
     
       printf("\n\n");
     
       o=n;
     
     
       for(i=2;i<o+1;i++)
     
       {
     
        	compt=0;
          for(j=2;j<i;j++)
     
          {
     
            	if(i%j==0)
     
             {
     
               	compt=compt+1;
     
             }
     
          }
     
     
     
          if(compt==0)
     
          {
     
            	prem[taille]=i;
     
             taille=taille+1;
     
          }
     
       }
     
     
     
       for(i=0;i<taille;i++)
     
       {
     
       	k=0;
     
        	while(fmod(o,prem[i])==0)
     
          {
     
          	o=o/prem[i];
     
             k=k+1;
     
             puissance[i]=k;
     
          }
     
       }
     
     
     
       printf("%d =",n);
     
     
     
       for(i=0;i<taille;i++)
     
       {
     
        	if(puissance[i]!=0)
     
          {
     
          	printf(" (%d",prem[i]);
     
       		printf("^");
     
       		printf("%d)",puissance[i]);
     
          }
     
       }
     
       getch();
     
    }
    /******************************************************************************/
    void Rsa::quitter(void)
     
    {
     
    	//clrscr();
     
     
     
       printf("\n\n\n\n\n\n\n\n\n");
     
       printf("       *     *   *	      ******   ****** *       * ****** * ******       \n");
     
       printf("      * *    *   *	      *    *   *       *     *  *    * * *    *       \n");
     
       printf("     *****   *   *            ******   ***      *   *   *    ** ******       \n");
     
       printf("    *     *  *   *	      *     *  *         * *    *    * * *     *      \n");
     
       printf("   *       * *****	      *      * ******     *     ****** *      *     \n");
     
     
     
    }
     
     
     
     
     
    /* Perform the SHS transformation.  Note that this code, like MD5, seems to
       break some optimizing compilers due to the complexity of the expressions
       and the size of the basic block.  It may be necessary to split it into
       sections, e.g. based on the four subrounds
     
       Note that this corrupts the shsInfo->data area */
     
    static void Rsa::SHSTransform( digest, data )
         UINT4 *digest, *data ;
        {
        UINT4 A, B, C, D, E;     /* Local vars */
        UINT4 eData[ 16 ];       /* Expanded data */
     
        /* Set up first buffer and local data buffer */
        A = digest[ 0 ];
        B = digest[ 1 ];
        C = digest[ 2 ];
        D = digest[ 3 ];
        E = digest[ 4 ];
        memcpy( (POINTER)eData, (POINTER)data, SHS_DATASIZE );
     
        /* Heavy mangling, in 4 sub-rounds of 20 interations each. */
        subRound( A, B, C, D, E, f1, K1, eData[  0 ] );
        subRound( E, A, B, C, D, f1, K1, eData[  1 ] );
        subRound( D, E, A, B, C, f1, K1, eData[  2 ] );
        subRound( C, D, E, A, B, f1, K1, eData[  3 ] );
        subRound( B, C, D, E, A, f1, K1, eData[  4 ] );
        subRound( A, B, C, D, E, f1, K1, eData[  5 ] );
        subRound( E, A, B, C, D, f1, K1, eData[  6 ] );
        subRound( D, E, A, B, C, f1, K1, eData[  7 ] );
        subRound( C, D, E, A, B, f1, K1, eData[  8 ] );
        subRound( B, C, D, E, A, f1, K1, eData[  9 ] );
        subRound( A, B, C, D, E, f1, K1, eData[ 10 ] );
        subRound( E, A, B, C, D, f1, K1, eData[ 11 ] );
        subRound( D, E, A, B, C, f1, K1, eData[ 12 ] );
        subRound( C, D, E, A, B, f1, K1, eData[ 13 ] );
        subRound( B, C, D, E, A, f1, K1, eData[ 14 ] );
        subRound( A, B, C, D, E, f1, K1, eData[ 15 ] );
        subRound( E, A, B, C, D, f1, K1, expand( eData, 16 ) );
        subRound( D, E, A, B, C, f1, K1, expand( eData, 17 ) );
        subRound( C, D, E, A, B, f1, K1, expand( eData, 18 ) );
        subRound( B, C, D, E, A, f1, K1, expand( eData, 19 ) );
     
        subRound( A, B, C, D, E, f2, K2, expand( eData, 20 ) );
        subRound( E, A, B, C, D, f2, K2, expand( eData, 21 ) );
        subRound( D, E, A, B, C, f2, K2, expand( eData, 22 ) );
        subRound( C, D, E, A, B, f2, K2, expand( eData, 23 ) );
        subRound( B, C, D, E, A, f2, K2, expand( eData, 24 ) );
        subRound( A, B, C, D, E, f2, K2, expand( eData, 25 ) );
        subRound( E, A, B, C, D, f2, K2, expand( eData, 26 ) );
        subRound( D, E, A, B, C, f2, K2, expand( eData, 27 ) );
        subRound( C, D, E, A, B, f2, K2, expand( eData, 28 ) );
        subRound( B, C, D, E, A, f2, K2, expand( eData, 29 ) );
        subRound( A, B, C, D, E, f2, K2, expand( eData, 30 ) );
        subRound( E, A, B, C, D, f2, K2, expand( eData, 31 ) );
        subRound( D, E, A, B, C, f2, K2, expand( eData, 32 ) );
        subRound( C, D, E, A, B, f2, K2, expand( eData, 33 ) );
        subRound( B, C, D, E, A, f2, K2, expand( eData, 34 ) );
        subRound( A, B, C, D, E, f2, K2, expand( eData, 35 ) );
        subRound( E, A, B, C, D, f2, K2, expand( eData, 36 ) );
        subRound( D, E, A, B, C, f2, K2, expand( eData, 37 ) );
        subRound( C, D, E, A, B, f2, K2, expand( eData, 38 ) );
        subRound( B, C, D, E, A, f2, K2, expand( eData, 39 ) );
     
        subRound( A, B, C, D, E, f3, K3, expand( eData, 40 ) );
        subRound( E, A, B, C, D, f3, K3, expand( eData, 41 ) );
        subRound( D, E, A, B, C, f3, K3, expand( eData, 42 ) );
        subRound( C, D, E, A, B, f3, K3, expand( eData, 43 ) );
        subRound( B, C, D, E, A, f3, K3, expand( eData, 44 ) );
        subRound( A, B, C, D, E, f3, K3, expand( eData, 45 ) );
        subRound( E, A, B, C, D, f3, K3, expand( eData, 46 ) );
        subRound( D, E, A, B, C, f3, K3, expand( eData, 47 ) );
        subRound( C, D, E, A, B, f3, K3, expand( eData, 48 ) );
        subRound( B, C, D, E, A, f3, K3, expand( eData, 49 ) );
        subRound( A, B, C, D, E, f3, K3, expand( eData, 50 ) );
        subRound( E, A, B, C, D, f3, K3, expand( eData, 51 ) );
        subRound( D, E, A, B, C, f3, K3, expand( eData, 52 ) );
        subRound( C, D, E, A, B, f3, K3, expand( eData, 53 ) );
        subRound( B, C, D, E, A, f3, K3, expand( eData, 54 ) );
        subRound( A, B, C, D, E, f3, K3, expand( eData, 55 ) );
        subRound( E, A, B, C, D, f3, K3, expand( eData, 56 ) );
        subRound( D, E, A, B, C, f3, K3, expand( eData, 57 ) );
        subRound( C, D, E, A, B, f3, K3, expand( eData, 58 ) );
        subRound( B, C, D, E, A, f3, K3, expand( eData, 59 ) );
     
        subRound( A, B, C, D, E, f4, K4, expand( eData, 60 ) );
        subRound( E, A, B, C, D, f4, K4, expand( eData, 61 ) );
        subRound( D, E, A, B, C, f4, K4, expand( eData, 62 ) );
        subRound( C, D, E, A, B, f4, K4, expand( eData, 63 ) );
        subRound( B, C, D, E, A, f4, K4, expand( eData, 64 ) );
        subRound( A, B, C, D, E, f4, K4, expand( eData, 65 ) );
        subRound( E, A, B, C, D, f4, K4, expand( eData, 66 ) );
        subRound( D, E, A, B, C, f4, K4, expand( eData, 67 ) );
        subRound( C, D, E, A, B, f4, K4, expand( eData, 68 ) );
        subRound( B, C, D, E, A, f4, K4, expand( eData, 69 ) );
        subRound( A, B, C, D, E, f4, K4, expand( eData, 70 ) );
        subRound( E, A, B, C, D, f4, K4, expand( eData, 71 ) );
        subRound( D, E, A, B, C, f4, K4, expand( eData, 72 ) );
        subRound( C, D, E, A, B, f4, K4, expand( eData, 73 ) );
        subRound( B, C, D, E, A, f4, K4, expand( eData, 74 ) );
        subRound( A, B, C, D, E, f4, K4, expand( eData, 75 ) );
        subRound( E, A, B, C, D, f4, K4, expand( eData, 76 ) );
        subRound( D, E, A, B, C, f4, K4, expand( eData, 77 ) );
        subRound( C, D, E, A, B, f4, K4, expand( eData, 78 ) );
        subRound( B, C, D, E, A, f4, K4, expand( eData, 79 ) );
     
        /* Build message digest */
        digest[ 0 ] += A;
        digest[ 1 ] += B;
        digest[ 2 ] += C;
        digest[ 3 ] += D;
        digest[ 4 ] += E;
        }
     
    /* When run on a little-endian CPU we need to perform byte reversal on an
       array of long words. */
     
    static void Rsa::longReverse(UINT4 *buffer, int byteCount, int Endianness )
    {
        UINT4 value;
     
        if (Endianness==TRUE) return;
        byteCount /= sizeof( UINT4 );
        while( byteCount-- )
            {
            value = *buffer;
            value = ( ( value & 0xFF00FF00L ) >> 8  ) | \
                    ( ( value & 0x00FF00FFL ) << 8 );
            *buffer++ = ( value << 16 ) | ( value >> 16 );
            }
    }
     
    /* Update SHS for a block of data */
     
    void Rsa::SHAUpdate(SHA_CTX *shsInfo, BYTE *buffer, int count)
    {
        UINT4 tmp;
        int dataCount;
     
        /* Update bitcount */
        tmp = shsInfo->countLo;
        if ( ( shsInfo->countLo = tmp + ( ( UINT4 ) count << 3 ) ) < tmp )
            shsInfo->countHi++;             /* Carry from low to high */
        shsInfo->countHi += count >> 29;
     
        /* Get count of bytes already in data */
        dataCount = ( int ) ( tmp >> 3 ) & 0x3F;
     
        /* Handle any leading odd-sized chunks */
        if( dataCount )
            {
            BYTE *p = ( BYTE * ) shsInfo->data + dataCount;
     
            dataCount = SHS_DATASIZE - dataCount;
            if( count < dataCount )
                {
                memcpy( p, buffer, count );
                return;
                }
            memcpy( p, buffer, dataCount );
            longReverse( shsInfo->data, SHS_DATASIZE, shsInfo->Endianness);
            SHSTransform( shsInfo->digest, shsInfo->data );
            buffer += dataCount;
            count -= dataCount;
            }
     
        /* Process data in SHS_DATASIZE chunks */
        while( count >= SHS_DATASIZE )
            {
            memcpy( (POINTER)shsInfo->data, (POINTER)buffer, SHS_DATASIZE );
            longReverse( shsInfo->data, SHS_DATASIZE, shsInfo->Endianness );
            SHSTransform( shsInfo->digest, shsInfo->data );
            buffer += SHS_DATASIZE;
            count -= SHS_DATASIZE;
            }
     
        /* Handle any remaining bytes of data. */
        memcpy( (POINTER)shsInfo->data, (POINTER)buffer, count );
        }
     
    /* Final wrapup - pad to SHS_DATASIZE-byte boundary with the bit pattern
       1 0* (64-bit count of bits processed, MSB-first) */
     
    void Rsa::SHAFinal(BYTE *output, SHA_CTX *shsInfo)
    {
        int count;
        BYTE *dataPtr;
     
        /* Compute number of bytes mod 64 */
        count = ( int ) shsInfo->countLo;
        count = ( count >> 3 ) & 0x3F;
     
        /* Set the first char of padding to 0x80.  This is safe since there is
           always at least one byte free */
        dataPtr = ( BYTE * ) shsInfo->data + count;
        *dataPtr++ = 0x80;
     
        /* Bytes of padding needed to make 64 bytes */
        count = SHS_DATASIZE - 1 - count;
     
        /* Pad out to 56 mod 64 */
        if( count < 8 )
            {
            /* Two lots of padding:  Pad the first block to 64 bytes */
            memset( dataPtr, 0, count );
            longReverse( shsInfo->data, SHS_DATASIZE, shsInfo->Endianness );
            SHSTransform( shsInfo->digest, shsInfo->data );
     
            /* Now fill the next block with 56 bytes */
            memset( (POINTER)shsInfo->data, 0, SHS_DATASIZE - 8 );
            }
        else
            /* Pad block to 56 bytes */
            memset( dataPtr, 0, count - 8 );
     
        /* Append length in bits and transform */
        shsInfo->data[ 14 ] = shsInfo->countHi;
        shsInfo->data[ 15 ] = shsInfo->countLo;
     
        longReverse( shsInfo->data, SHS_DATASIZE - 8, shsInfo->Endianness );
        SHSTransform( shsInfo->digest, shsInfo->data );
     
    	/* Output to an array of bytes */
    	SHAtoByte(output, shsInfo->digest, SHS_DIGESTSIZE);
     
    	/* Zeroise sensitive stuff */
    	memset((POINTER)shsInfo, 0, sizeof(shsInfo));
    }
     
    static void Rsa::SHAtoByte(BYTE *output, UINT4 *input, unsigned int len)
    {	/* Output SHA digest in byte array */
    	unsigned int i, j;
     
    	for(i = 0, j = 0; j < len; i++, j += 4) 
    	{
            output[j+3] = (BYTE)( input[i]        & 0xff);
            output[j+2] = (BYTE)((input[i] >> 8 ) & 0xff);
            output[j+1] = (BYTE)((input[i] >> 16) & 0xff);
            output[j  ] = (BYTE)((input[i] >> 24) & 0xff);
    	}
    }
    }
     
     
     
    /* Output should look like:-
     a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d
     A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D <= correct
     84983e44 1c3bd26e baae4aa1 f95129e5 e54670f1
     84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 <= correct
     34aa973c d4c4daa4 f61eeb2b dbad2731 6534016f
     34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F <= correct
    */
     
     
     
    /*************************************END**************************************/
    Rsa.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    #ifndef RSA_H_INCLUDED
    #define RSA_H_INCLUDED
    #ifndef _ENDIAN_H_
    #define _ENDIAN_H_ 1
     
     
    #ifndef _GLOBAL_H_
    #define _GLOBAL_H_ 1
    #ifndef _SHA_H_
    #define _SHA_H_ 1
    #ifndef TRUE
    #define FALSE	0
    #define TRUE	( !FALSE )
    /* The SHS block size and message digest sizes, in bytes */
     
    #define SHS_DATASIZE    64
    #define SHS_DIGESTSIZE  20
     
     
     
    #define f1(x,y,z)   ( z ^ ( x & ( y ^ z ) ) )           /* Rounds  0-19 */
    #define f2(x,y,z)   ( x ^ y ^ z )                       /* Rounds 20-39 */
     
    #define f3(x,y,z)   ( ( x & y ) | ( z & ( x | y ) ) )   /* Rounds 40-59 */
    #define f4(x,y,z)   ( x ^ y ^ z )                       /* Rounds 60-79 */
     
    /* The SHS Mysterious Constants */
     
    #define K1  0x5A827999L                                 /* Rounds  0-19 */
    #define K2  0x6ED9EBA1L                                 /* Rounds 20-39 */
    #define K3  0x8F1BBCDCL                                 /* Rounds 40-59 */
    #define K4  0xCA62C1D6L                                 /* Rounds 60-79 */
     
    /* SHS initial values */
     
    #define h0init  0x67452301L
    #define h1init  0xEFCDAB89L
    #define h2init  0x98BADCFEL
    #define h3init  0x10325476L
    #define h4init  0xC3D2E1F0L
     
     
     
    #define ROTL(n,X)  ( ( ( X ) << n ) | ( ( X ) >> ( 32 - n ) ) )
     
     
     
    #define expand(W,i) ( W[ i & 15 ] = ROTL( 1, ( W[ i & 15 ] ^ W[ (i - 14) & 15 ] ^ \
                                                     W[ (i - 8) & 15 ] ^ W[ (i - 3) & 15 ] ) ) )
     
     
     
     
    #define subRound(a, b, c, d, e, f, k, data) \
        ( e += ROTL( 5, a ) + f( b, c, d ) + k + data, b = ROTL( 30, b ) )
     
     
     
    #include <string>
     
    class Rsa
    {
        public:
            Rsa();
            ~Rsa();
           typedef struct 
            {
    	UINT4 digest[ 5 ];            /* Message digest */
    	UINT4 countLo, countHi;       /* 64-bit bit count */
    	UINT4 data[ 16 ];             /* SHS data buffer */
    	int Endianness;
              } SHA_CTX;
          typedef unsigned char *POINTER;/* POINTER defines a generic pointer type */
          typedef unsigned long int UINT4;/* UINT4 defines a four byte word */
          typedef unsigned char BYTE; /* BYTE defines a unsigned character */
     
            void menu(void);
            void quitter(void);
            void erreur(void);
            void menu_crypto(void);
            void menu_calcul(void);
            void pgcd(void);
            void choix_calcul(void);
            void modulo(void);
            void p_e_e(void);
            void primarite(void);
            void choix_crypto(void);
            void lecture(void);
            void comparer(void);
            unsigned long int crypt(unsigned char k,unsigned long int n,unsigned long int e);
            unsigned char decrypt( unsigned long int k,unsigned long int d,unsigned long int n);
            void crypter(void);
            void decrypter(void);
            void inscri(void);
            int p_e_e2(int x);
            void pgcd2(int a,int b,int* taille,int* tab[]);
            void decomp(int*s,int*q,int*r,int*k);
            int cle_priv(int e,int z);
            void pq(int* p,int* q);
            void decomposition(void);     
            void hachage();
            void SHAInit(SHA_CTX *shsInfo);
            void SHAFinal(BYTE *output, SHA_CTX *);
            static void SHAtoByte(BYTE *output, UINT4 *input, unsigned int len);
            void SHAInit(SHA_CTX *);
            void SHAUpdate(SHA_CTX *, BYTE *buffer, int count);
            void SHAFinal(BYTE *output, SHA_CTX *);
            void endianTest(int *endianness);
            static void SHAtoByte(BYTE *output, UINT4 *input, unsigned int len);
            static void SHSTransform( digest, data );
            static void longReverse(UINT4 *buffer, int byteCount, int Endianness );
     
    };
     
    #endif // RSA_H_INCLUDED

  8. #8
    Membre confirmé Avatar de saad.hessane
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    315
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 315
    Points : 496
    Points
    496
    Par défaut

    Ce code aussi tu l'as téléchargé d'internet ? En gros ta classe RSA est un ensemble de fonction C que tu as téléchargé ici et là. Non mais sérieusement tu comptes apprendre comme ça? Même ton prof te collera un 0. Une bête recherche sur le nom d'une constante et j'ai l'une des sources d'où tu as téléchargé ton code.
    Si tu dois faire un copier coller essaie au moins de le comprendre.
    Excuse-moi, mais je ne suis pas très motivé pour lire 1500 lignes de code.
    Essaye de comprendre.

  9. #9
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut
    merci pour votre réponse
    ce code est mon enseignant l'envoyé afin que je le changé selon mes besoins
    mais j'ai compris comment fonctionne rsa et au le code que je vous envoyé ligne par ligne mais je veux le changer pas à pas ,puisque il n'y a pas le code rsa sous ns3 ,il y a de code sous quelque logiciel mais comme que je veux n'existe pas.
    Mon problème juste quelqu'un m'aider pour que le fonction au lieu de taper une valeur d'après clavier et puis en scanf ,je veux que mon programme choisit le nombre premier qui sont situe dans la liste des valeurs a et b
    et le reste de code je le changé après jusqu'à que j'aboutisse au code final

  10. #10
    Membre confirmé Avatar de saad.hessane
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    315
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 315
    Points : 496
    Points
    496
    Par défaut
    Le fait est que tu utilises des tableaux de nombres premiers. La fonction que tu as fournies est une fonction qui calcule le PGCD.
    Si "p" est un nombre premier, et "q" un nombre premier, alors pgcd(p, q) est toujours égal à 1.
    Pourquoi veux tu faire ça? A aucun moment RSA ne demande de calculer le pgcd de deux nombres premiers (Aucun algorithme ne le demande d'ailleurs parce que ça ne sert à rien)

  11. #11
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut
    salut
    le principe de RSA
    1-Trouver deux nombres premiers p et q distincts p et q doivent rester secrets)

    2.Calculer n = p × q.

    3.Choisir M tel que son PGCD avec (p-1)×(q-1) soit 1
    4 cle publique (n,M)
    5.Trouver d tel que
    M × d =1 (mod (p-1) ×(q-1))
    6- cle prive (n,d)
    donc ,je suis dans la premier etape ,je ne veux pas que l'utilisateur donne les nombres premiers, je veux que le programme l'a pris d'apres une liste enregistre,alors la je veux supprimer le pgcd entre les deux nombres puisqu'ils sont autoamtiquement des entiers premier
    ceça tous simplement mon demande ,

  12. #12
    Membre confirmé Avatar de saad.hessane
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    315
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 315
    Points : 496
    Points
    496
    Par défaut
    Non, non, et non.
    La première étape consiste à choisir p et q premier. Je te montre plus loin comment choisir au hasard un nombre premier dans ton tableau. Dans la troisième étape il te faut choisir M tel qu'il est premier avec (p-1)(q-1). Tu as obligatoirement besoin du pgcd.
    Tu vois pourquoi je te dis que tu n'as pas compris RSA.

    Si tu veux choisir un nombre au hasard il faut utiliser un générateur de nombre aléatoire. La fonction utilisée en C est rand().
    Supposons que ton tableau possède 10 éléments. Tu veux choisir un élément au hasard. Choisir un élément au hasard revient à choisir un indice de tableau au hasard. Il y a 10 indices , de 0 à 9 inclus.
    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    int tab[10];//={liste de tes nombres premiers}
    int indice;
     
    //Avant d'utiliser rand il faut initialiser le générateur de nombre aléatoire
    srand (time(NULL));
    indice = rand() % 10;
    tab[indice] est un élément choisie de manière aléatoire dans ton tableau.

  13. #13
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut
    merci bcp
    mais j'ai compris RSA , je suis en premier etape donc je n'a pas besoin de le pgcd je le supprime quand le pet q sont premier.mais lorsque j'abouti l'etape de m bien j'utilise le pgcd.alors je corrige le code selon votre conseil est ceque ça marche ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    int tabp[80]= {23, 29, 31, 37, 41, 43, 47,53, 59, 61, 67, 71, 73, 79, 83 ,89 ,97, 101, 103, 107, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 461, 463, 467, 479, 487, 491, 499,  503, 509, 521,653, 659, 661, 673, 677, 683, 691,  701, 709, 719, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857 };
    tabq[80]={109 ,113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337,401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929}
    tabm[80]={23, 29, 31, 37, 41, 43, 47,53, 59, 61, 67, 71, 73, 79, 83 ,89 ,97, 101, 103, 107, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 461, 463, 467, 479, 487, 491, 499,  503, 509, 521,653, 659, 661, 673, 677, 683, 691,  701, 709, 719, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857 };
    int p,q,n,s,m,k,b;
     //Avant d'utiliser rand il faut initialiser le générateur de nombre aléatoire
    srand (time(NULL));
    p = rand() % 80;
    q= rand() % 80;
    n=p*q;
    k=(p-1)×(q-1);
    int tabb[50]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 461 }
    b= rand() % 50;
       //Calcule du PGCD
      s=k;
      q=b;
      reste=s%q;
      while(reste>0)
      {
        s=q;
        q=reste;
        reste=s%q;
      }
     
      //Affichage du résultat
      if(q==1)
      {
        printf("\n\n%d et %d sont premiers entre eux.",k,b);
      }
      else
      {
        printf("\n\n%d et %d ne sont pas premiers entre eux.",k,b);
     
      }
    }

  14. #14
    Membre confirmé Avatar de saad.hessane
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    315
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 315
    Points : 496
    Points
    496
    Par défaut
    Bonjour,
    Je crois que le problème vient des nombres premiers entre eux.
    Connais-tu la différence entre un nombre premier, et deux nombres premiers entre eux?
    5 est un nombre premier, 23 est un nombre premier...
    4 n'est pas un nombre premier, 9 n'est pas un nombre premier.
    Mais 4 et 9 sont premier entre eux.
    Tu connais cette différence?

    [EDIT]
    Les pages wikipedia en arabe d'un nombre premier, et de deux nombres premiers entre eux

  15. #15
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut
    salut
    ui je connais ce difference ,mais pour ne pas laisser une chose au hasard :je choisit tous les nombres sont premiers:alors la quelques soit le nombre par rand () sorti :il est obligatoirement deux premiers entre eux

  16. #16
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut
    Citation Envoyé par chirazch Voir le message
    salut
    ui je connais ce difference ,mais pour ne pas laisser une chose au hasard :je choisit tous les nombres sont premiers:alors la quelques soit le nombre par rand () sorti :il est obligatoirement deux premiers entre eux ausii pour connaitre est ce que les sont prmeier ou non :on va chaque nomre diviser en nomre premier par exemple
    15= 3*5
    8=2 EXP 3
    8 ET 15 sont premier entre eux malgres qui sont deux nombres non prmeiers

  17. #17
    Membre confirmé Avatar de saad.hessane
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    315
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 315
    Points : 496
    Points
    496
    Par défaut
    Ta supposition est fausse :
    Première étape : je choisie deux nombres premiers au hasard : 5 et 13
    Deuxième étape : je choisie M nombre premier au hazard : 3
    (5-1)*(13-1) = 48
    Problème : 48 et 3 ne sont pas premiers entre eux. Algorithme RSA n'est pas respecté...

    Tu veux peut être que je choisisse des nombres des tableaux que tu as fournis :
    Première étape : je choisie deux nombres premiers au hasard : p=47 et q=109
    Deuxième étape : je choisie M nombre premier au hazard : 23
    (47-1)*(109-1)=4968.
    Problème : 4968 et 23 ne sont pas premiers entre eux...
    Algorithme RSA n'est pas respecté...
    ...

  18. #18
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut
    alors devant moi ilya deux choix
    1- je laisse la printf et scanf pour que l'utilsateur choisit M premieer selon le resulat qu'il observé de produit
    2-j'eliemne le rand dans les valeur de a et b seront
    par exemple: 23et 109 alors on assigné 17 il est premieux avec le produi (22*109)
    on choisit 5 et 13 alors on affecte 11 est un nbre premier avec le produit (4*12)
    et extra
    je prefere faire la 2 eme choix pour eliminer l'interaction avec l'utilisateur
    mais comment programmer

  19. #19
    Membre confirmé Avatar de saad.hessane
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    315
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 315
    Points : 496
    Points
    496
    Par défaut
    Non, tu choisis juste un nombre M entre 1 et (p-1)*(q-1) tel que (p-1)*(q-1) modulo M différent de 0.
    Les nombres premiers étant impaires (à part 2), tu peux commencer à partir de 3.
    L'idée de base est de chercher jusqu'à trouver celui qui convient.

    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    int phi = (p-1)*(q-1);
    int M=3;
    while( (phi % M) == 0 && (M < phi) )
    {
      M++;
    }

    Ton code en haut est faux. p=tabp[rand() % 80]
    Pour q aussi.

  20. #20
    Nouveau Candidat au Club
    Femme Profil pro
    etudiante
    Inscrit en
    Avril 2010
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2010
    Messages : 43
    Points : 0
    Points
    0
    Par défaut
    je vous remercie

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [SP-2007] Erreur 404 après ajout d'un nouvel element dans une liste
    Par peyrard dans le forum SharePoint
    Réponses: 6
    Dernier message: 26/10/2011, 18h20
  2. Réponses: 0
    Dernier message: 28/09/2011, 17h32
  3. Réponses: 2
    Dernier message: 04/01/2007, 13h31
  4. Réponses: 3
    Dernier message: 16/08/2006, 15h11
  5. Réponses: 11
    Dernier message: 11/08/2006, 16h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo