SHARE
TWEET

Untitled

iyed May 21st, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Program bac2;
  2.  
  3. Uses Wincrt;
  4.  
  5. Var
  6.   ch: String;
  7.  {*****************
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  ********************}
  14.  
  15.  
  16.  function estPremier(n:Integer):Boolean;
  17.  var good:Boolean;
  18.  i:Integer;
  19.  Begin
  20.             if(n=2)Then
  21.             Begin
  22.                     estPremier := true;
  23.                     exit;
  24.             end;
  25.  
  26.             {****** pas necessaire car longuer de ch > 4 ******}
  27.  
  28.  
  29.  
  30.            
  31.             i := 2;
  32.             good := true;
  33.             repeat
  34.            
  35.             if((n mod i) = 0) Then
  36.             good := false;
  37.  
  38.             i := i+1;
  39.  
  40.  
  41.             until not good or (i=n);
  42.             estPremier := good;
  43.  
  44.  end;
  45.  {*****************
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  ********************}
  52.  
  53. Function valide(ch1:String): Boolean;
  54. Begin
  55. valide := (Length(ch1) > 4) and ( not estPremier(Length(ch1)) );
  56. End;
  57.  {*****************
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  ********************}
  65. Procedure Remplir(Var ch2:String);
  66. Begin
  67.   Repeat
  68.     Writeln ('Donner une chaĆ®ne:');
  69.     Readln (ch2);
  70.   Until valide(ch2);
  71. End;
  72.  {*******************
  73.  
  74.  
  75.  
  76.  
  77. *************}
  78.  
  79.  
  80. Procedure doTheSwaps(Var ch1:String;each:Integer);
  81. var indx:Integer;
  82. tmp:char;
  83. newCh,total:String;
  84. Begin
  85.     newCh := '';
  86.     total := '';
  87.     for indx:=1 to Length(ch1) Do
  88.     Begin
  89.              newCh := ch1[indx] + newCh;
  90.              if(indx mod each) = 0 Then
  91.              Begin
  92.              total := total + newCh;
  93.              newCh := '';
  94.              end;
  95.     end;
  96.     ch1 := total + newCh;
  97. End;
  98.  
  99.  
  100. {*******************
  101.  
  102.  
  103.  
  104.  
  105. *************}
  106.  
  107.  
  108. function Encrypt(ch1:String):String;
  109. var i:Integer;
  110. Begin
  111.          for i := 2 to  length(ch1)-1 Do
  112.          Begin
  113.                  if(length(ch1) mod i)=0 Then
  114.                  doTheSwaps(ch1,i);
  115.          end;
  116.          Encrypt :=  ch1;
  117. end;
  118.  
  119.  
  120.  
  121. {*******************
  122.  
  123.  
  124.  
  125.  
  126. *************}
  127.  
  128. Begin
  129.         Remplir(ch);
  130.         writeLn(Encrypt(ch));
  131.  
  132.  
  133. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top