Request for Circular Shift Functions
07-19-2015, 07:54 PM
Post: #1
 douganc Junior Member Posts: 34 Joined: Sep 2014
Request for Circular Shift Functions
Hello,

Could you please add Circular Shift Functions for both Lists Type and Binary Bits Type to the HP Prime and also Xcas.

These Functions would be very useful for teaching Elementary Cryptography and also Programming.

I am thinking of a fun elementary cryptography App. on HP Prime, where the teacher and students could send encrypted text to each other using basic methods like Caesar Shift and Block Codes. Then students would decode received message using supplied algorithms they learn about in Class.

/*
* Shift operations in C are only defined for shift values which are
* not negative and smaller than sizeof(value) * CHAR_BIT.
*/
Rotate Left Example:

unsigned int rotl(unsigned int value, int shift) {
return (value << shift) | (value >> (sizeof(value) * CHAR_BIT - shift));
}
Rotate Right Example:

unsigned int rotr(unsigned int value, int shift) {
return (value >> shift) | (value << (sizeof(value) * CHAR_BIT - shift));
}

Thanks !
Colm
07-20-2015, 01:00 AM
Post: #2
 roadrunner Senior Member Posts: 446 Joined: Jun 2015
RE: Request for Circular Shift Functions
Hello Colm,

Is this what you mean?

For lists:
Code:

LOCAL s;

EXPORT listright(t)
BEGIN
IF type(t)≠6 THEN RETURN ;END;
s:=SIZE(t);
RETURN CONCAT(t(s),SUB(t,1,s-1));
END;

EXPORT listleft(t)
BEGIN
IF type(t)≠6 THEN RETURN ;END;
s:=SIZE(t);
RETURN CONCAT(SUB(t,2,s),t(1));
END;

For bits:
Code:

EXPORT bitleft(t)
BEGIN
RETURN BITSL(t,1)+BITSR(t,GETBITS(t)-1);
END;

EXPORT bitright(t)
BEGIN
RETURN BITSR(t,1)+BITSL(t,GETBITS(t)-1);
END;

07-20-2015, 06:07 AM
Post: #3
 douganc Junior Member Posts: 34 Joined: Sep 2014
RE: Request for Circular Shift Functions
Yes, thank you.
Perhaps now they put functions in operating system.
Thank you
Colm [/i]
07-20-2015, 07:16 PM
Post: #4
 douganc Junior Member Posts: 34 Joined: Sep 2014
RE: Request for Circular Shift Functions
Hello,
Could you please put these programs in the Hp Prime Software Section.
So everyone can use in their programs.
Thank You.
Colm
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)