Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atbash Cipher Error #148

Closed
Koch013 opened this issue Apr 28, 2022 · 9 comments
Closed

Atbash Cipher Error #148

Koch013 opened this issue Apr 28, 2022 · 9 comments
Assignees

Comments

@Koch013
Copy link

Koch013 commented Apr 28, 2022

I receive the following error while running the tests online:

./zcl_atbash_cipher.clas.abap[50, 5] - "txt_len" not found, findTop (check_syntax) [E]
abaplint: 1 issue(s) found

Here's my code, which works fine on my local system:

CLASS zcl_atbash_cipher DEFINITION PUBLIC FINAL CREATE PUBLIC.

  PUBLIC SECTION.
    METHODS decode
      IMPORTING
        cipher_text TYPE string
      RETURNING
        VALUE(plain_text)  TYPE string .
    METHODS encode
      IMPORTING
        plain_text        TYPE string
      RETURNING
        VALUE(cipher_text) TYPE string .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zcl_atbash_cipher IMPLEMENTATION.

  METHOD decode.
   plain_text =  translate( val = |{ condense( val = to_lower( cipher_text ) from = ` ,.:;` TO = `` )  }|
                              from = |{ REVERSE( to_lower( sy-abcde ) ) && `0123456789` }|
                              to = |{ to_lower( sy-abcde ) && `0123456789` }|
                               ).
  ENDMETHOD.

  METHOD encode.
    cipher_text =  translate( val = |{ condense( val = to_lower( plain_text ) from = ` ,.:;` TO = `` )  }|
                              from = |{ to_lower( sy-abcde ) && `0123456789` }|
                              TO = |{ REVERSE( to_lower( sy-abcde ) ) && `0123456789` }| ).
    cipher_text = REDUCE string( LET txt_len = STRLEN( cipher_text ) IN
                            INIT text = `` offset = 0 sep = ``
                            FOR i = 1 UNTIL i > round( val = ( txt_len / 5 ) dec = 0 mode = cl_abap_math=>round_up )
                            NEXT text = text && sep &&
                                       substring( val = cipher_text off = offset
                                       len = nmin( val1 = 5
                                                   val2 = txt_len - offset )
                                                )
                                 sep = ` ` offset = i * 5 ).

  ENDMETHOD.

ENDCLASS.
@larshp
Copy link
Member

larshp commented Apr 28, 2022

thanks 👍

@larshp
Copy link
Member

larshp commented Apr 29, 2022

reproduced as

DATA(text) = REDUCE string(
  LET txt_len = strlen( |dfsdfs| ) IN
  INIT foo = ``
  FOR i = 1 UNTIL i > txt_len
  NEXT foo = foo && |sdf| ).

image

@larshp
Copy link
Member

larshp commented Apr 29, 2022

@larshp
Copy link
Member

larshp commented Apr 29, 2022

next problem: the downport ignores txt_len

@larshp
Copy link
Member

larshp commented Apr 29, 2022

@larshp
Copy link
Member

larshp commented May 1, 2022

abaplint/transpiler#726

@larshp
Copy link
Member

larshp commented May 2, 2022

now got 6 passing,

image

@larshp
Copy link
Member

larshp commented May 3, 2022

@Koch013 try again

image

@Koch013
Copy link
Author

Koch013 commented May 4, 2022

Works now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants