Permalink
Browse files

Update to v0.0.2

  • Loading branch information...
nelbren committed Oct 23, 2018
1 parent 3bc139e commit d32be705aae9f67bc0535c747cda2ce562c70734
Showing with 16 additions and 39 deletions.
  1. +1 −0 .gitignore
  2. +3 −7 heart.rb
  3. +6 −19 shift_cipher.c
  4. +3 −10 shift_cipher.rb
  5. +3 −3 string_rotations.rb
@@ -0,0 +1 @@
shift_cipher.c.bin
@@ -1,7 +1,7 @@
#!/usr/bin/ruby
# heart.ruby v0.0.1
# heart.ruby v0.0.2
# nelbren@gmail.com
# First try!
# Use: Shortened if
@a = ['','','','','','','','']
8.times do |r|
@@ -19,11 +19,7 @@
@cb = @cb + 1
end
7.times do |c|
if (@cb..@ce).include?(c)
@a[r] += 'x'
else
@a[r] += ' '
end
@a[r] += (@cb..@ce).include?(c) ? 'x' : ' '
end
end
@@ -1,31 +1,18 @@
/* shift_cipher_v0.0.1.c
/* shift_cipher_v0.0.2.c
nelbren@nelbren.com
UseShiftCipherIn28lines */
UseTernaryOperatorIn15lines */
#include <stdio.h>
#include <string.h> // strlen
#include <stdlib.h> // malloc
char *shift_str(char *x, int d) {
size_t len = strlen(x);
char *r = malloc(sizeof(char) * len);
for(int i = 0; i < len; i++) {
char na;
if (x[i] == 32)
na = x[i];
else {
na = x[i] + d;
if (na > 90)
na = na - 90 + 64;
}
r[i] = na;
}
r[len] = '\0';
return r;
for(int i = 0; i < len; i++) r[i] = x[i] == 32 ? x[i] : (x[i] + d > 90 ? x[i] + d - 26 : x[i] + d);
r[len] = '\0'; return r;
}
void cipher2text(char *x) {
for(int d = 0; d < 25; d++)
printf("intento #%02d: %s\n", d, shift_str(x,d));
for(int d = 0; d < 25; d++) printf("intento #%02d: %s\n", d, shift_str(x,d));
}
int main() {
cipher2text("PHHW PH DIWHU WKH WRJD SDUWB");
return 0;
cipher2text("PHHW PH DIWHU WKH WRJD SDUWB"); return 0;
}
@@ -1,18 +1,11 @@
#!/usr/bin/ruby
# shift_cipher_v0.0.1.rb
# shift_cipher_v0.0.2.rb
# nelbren@nelbren.com
# UseShiftCipherIn20lines
# UseTernaryOperatorIn13lines
def shift_str(x,d)
r=''
x.each_byte do |c|
if (c == 32)
na=c
else
na=c+d
if (na > 90)
na = na - 90 + 64
end
end
na = c == 32 ? c : (c + d > 90 ? c + d - 26 : c + d)
r=r+na.chr
end
r
@@ -1,5 +1,5 @@
#!/usr/bin/ruby
# string_rotations_v0.0.1.rb
# string_rotations_v0.0.2.rb
# nelbren@nelbren.com
# UsingSubstring
x=gets.chomp;a=[];x.each_char{|c|x=x[1..-1]+c;a<<x};p a
# UsingRotate
x=gets.chomp;a=[];x.size.times{a<<x=x.chars.rotate(1).join};p a

0 comments on commit d32be70

Please sign in to comment.