Basis - Authorization for Customise Program
Hi,
In Customise Program they give the Tcode, Ex: ZMMR001
how to control the Oranization Level & Plant in Authorization.
Pls explain.
Thanks
Hi,
You should check with your basis. Every company create there own objects as per there need.
Regards,
Atish
Similar Messages
-
How to give user authorizations for a Program or an ICF service
Hi,
1)How to give user authorizations for a report program or an ICF service.
2)How to create an user authorization object.
Regards,
Vinay.check this online help for more info on authorization object creation
http://help.sap.com/saphelp_nw04/helpdata/en/52/67168c439b11d1896f0000e8322d00/frameset.htm
for question no1.
ICF - you either maintain the auth obj relevant at the icf service level itself or you can code call authority object and block access
for abap programs:
you maintain auth object at the tcode or code the call authority object within the program
Regards
Raja -
Authorization for Z Program for creating entries
I have created a dialog program to maintain employee details with menus Create, Change, Display
My concern is that i want to restrict some user for creating entries in database table through this dialog program those users only authorize to display data.
Please guide me how to do achieve above.
ThanksHi,
You can make use of the system variable sy-uname which holds the user logon name. Based on this u can decide whether to allow the user in edit mode or display mode.
Regards,
Naga Sai -
Hi
I have created a role with authorization for VF01 transaction. however when I try to execute the transaction VF01 it gives me an error. When I do SU53 it gives e an error for missing authorization object S_DOKU_AUT.
Do we need to create a role with some common basis authorizations for each user. If yes, what are those common authorizations.
Thanks
Deepakhi,
open the role that you have created for VF01 authorization by T-code PFCG
click on authorization tab in that open change authorization and manually add this object S_DOKU_AUT
to this role and change the activity according to your requirement .generate the profile and assigened to the user. -
Authorization for a custom programme
How to do Authorization for Custom Transactions?
Can we directly put Authorization Object name in SE93?
What should be the default values? How can we authorize - User Input values in Program T-Code?
How to do Authorization for Custom Programs?
This is usually done by incuding:
AT SELECTION-SCREEN .
AUTHORITY-CHECK OBJECT 'F_RE_TRANS' ID1 Authorization field1 FIELD1 Authorization field value1
ID2 Authorization field2 FIELD2 Authorization field value2
IF sy-subrc = 4.
Display No Authorization error
ENDIF.
If we donot want to pass the Authorization field - Activity Code ACTVT as Display/Change/Create etc., what should be passed in ACTVT, can we leave it ' ' ?
How to do Authorization for Table Maintainance Transactions?
Can we directly put Authorization Object name in SE11 Table Maintainance Generator?
If how to determine Authorization Group?
What should be the default values?
How can we authorize - User Input values in Table maintainance T-Code?
Can we use transaction SU22? If so how?Hi Friend,
SU21- for creating authorization object
SU20 - for creating authorization field and assign with authorization object
SU22 - maintain authorization agianst transactions
Execute these transactions or see any standard object you will understand everything.
Regards
Krishnendu -
BASIS--to restrict authorization for a PO document type & 122 movement type
Dear All,
Plz guide me how to restrict authorization for a PO document type & for a movement type 122 i.e. for eg. if a user has authorization for PO document type IC then he should not be able to rum movement type 122 for any T-code he runs.
Thanks in advance
Arpit
BasisHi,
Your request was not too clear to me.. As per my unde
Here is some details of Authorization object related to Purchase Order:
Document Type in Purchase Order( M_BEST_BSA )
Purchasing Group in Purchase Order (M_BEST_EKG )
Purchasing Organization in Purchase Order (M_BEST_EKO)
Plant in Purchase Order (M_BEST_WRK )
Document Type in Outline Agreement (M_RAHM_BSA )
Purchasing Group in Outline Agreement (M_RAHM_EKG )
Purchasing Organization in Outline Agreement ( M_RAHM_EKO )
Plant in Outline Agreement ( M_RAHM_WRK )
This can be helpfull to you to restrict authorization to PO..
In Organization Level, it can be restricted by Purchasing group, Purchasing organization and plant..
Regards,
Sandip -
Display authorization for all modules Including Basis.
Hi All,
Is there any Role or profile for display authorization for sap modules .
Regards,
Eswar.Dear,
That ROLE will be SAP_ALL_DISPLAY
"what is to be done"
just assign the role to the display user via SU01
Hope this help!
Also refer this ,
DISPLAY ONLY AUTHORIZATION
Regards,
R.Brahmankar -
Cancel a SD invoice error message "no authorization for transaction FB08"
Hi Gurus,
I am trying to cancel a SD invoice and am receiving the error message " no authorization for transaction FB08" is coming. Never has this happened in past, i have checked all the security authorizations also and they are in place. Accounting document status is showing as not cleared. Also, as per my understanding cancellation of invoice happens through VF11 which does not calls FB08. Please point out reasons as to why this could be happening and the possible solution thereof.
regards
Anmol PareekHi Anmol
Once you got the error screen, immediately after that goto T code SU53 and expand all link. Take the screen shot and send it to your BASIS team to provide you proper access.
Yes you are correct cancellation is done through VF11 but sometime some programs internally calls other T codes.
take help of your basis team. -
Hi Gurus,
While executing the program S_ALR_87013105 (Detailed Reports
For Sales Order : Plan/Actual Comparison ) system showing the selection log.
"Have no authorization for the report/table 7KU6_001 and 7KU6_002".
But for the user the authorization check through SU53 was successful.
Pl can any one suggest on this issue.
Thanks in advance,
VijayHi,
Contact your basis consultant to provide the missing authorisation. This is one of the authorisation object.
Regards,
Sankar -
Include an authorization check in program
Hello,
I am new to SDN .
I got a requirement where i have to include an authorization check in programs this is required for all custom programs before they are added to roles . I am not sure what i have to do it .
These programs if i try to open in se38 , i cannot view them .
How do i include authorisation checks .
Please let me know step by step .
i will be grateful.
thanks
sumit
Edited by: sumit123 on Jan 20, 2010 9:52 AMHi Sumit,
http://help.sap.com/saphelp_nw04s/helpdata/en/52/67129f439b11d1896f0000e8322d00/content.htm
Check this link.
The following actions are authorization checks that are performed before the start of a program or table maintenance and which the SAP applications cannot avoid: .
1.Starting SAP transactions (authorization object S_TCODE)
2.Starting reports (authorization object S_PROGRAM)
3.Calling RFC function modules (authorization object S_RFC)
4.Table maintenance with generic tools (S_TABU_DIS)
Authority check is done to restrict the execution of a report to certain users.
Basis creates a authorisation group , includes certain roles in it, to which authorisation should be given.
If one's id has that role then he is authorised to execute the report..
IN the report the below code is written to do auth. check
Authority check on plant
AUTHORITY-CHECK OBJECT 'ZMMD_PROD'
ID 'WERKS' FIELD wf_werks.
Here authorisation is done on plant. and the authorisation object is ZMMD_PROD(to be created by BASIS) -
Function Module for authorization for ztable
Hi All,
I created one ZTABLE .I am adding,changing and delete data into that ZTABLE through program from upload one excel file.But before adding ,changing and delete data to that ZTABLE, first check whether that USER have authorization (Addition, Deletion or Modification) of a particular Ztable, If the user is NOT authorized, an appropriate message will be displayed and the program will return to the selection Screen.I heard about FM 'AUTHORITY_CHECK_TABL' But i dnt know how to pass parameters.If iam right then give me how to use that Function module.then i can proceed.If there are any other function modules ,please provide with examples then i can understand clearly.Please help me regards ASAP.
ABHI..Hi Abdul,
Please follow the steps:
Go to transaction SE54.
1. Create an authorization group.
2. After creating authorization group
You should assign authorization group for the table in question in the same transaction.
Now this has been done, you should use authorization object 'S_TABU_DIS' in the program
The usage is:
AUTHORITY-CHECK OBJECT 'S_TABU_DIS'
ID 'DICBERCLS' FIELD <authorizationgroup>
ID 'ACTVT' FIELD <activity>. 1 - creation, 2-modification, 3-display
IF sy-subrc NE 0.
MESSAGE e000(zxxx).
EXIT.
ENDIF.
You can speak with your basis admin for authorization to the users.
Just give the authorization group name, they will do it for you.
Thanks and regards,
S. Chandra Mouli. -
Want Authorization for SM30 in particular table
Hi friends,
i am created a ztable and also created table maintanence generator.
now my problem is, i want to Authorization for SM30 in particular table.
Thanks & Rgards,
Vallamuthu.MHi this will help u.
In general different users will be given different authorizations based on their role in the orgn.
We create ROLES and assign the Authorization and TCODES for that role, so only that user can have access to those T Codes.
USe SUIM and SU21 T codes for this.
Much of the data in an R/3 system has to be protected so that unauthorized users cannot access it. Therefore the appropriate authorization is required before a user can carry out certain actions in the system. When you log on to the R/3 system, the system checks in the user master record to see which transactions you are authorized to use. An authorization check is implemented for every sensitive transaction.
If you wish to protect a transaction that you have programmed yourself, then you must implement an authorization check.
This means you have to allocate an authorization object in the definition of the transaction.
For example:
program an AUTHORITY-CHECK.
AUTHORITY-CHECK OBJECT <authorization object>
ID <authority field 1> FIELD <field value 1>.
ID <authority field 2> FIELD <field value 2>.
ID <authority-field n> FIELD <field value n>.
The OBJECT parameter specifies the authorization object.
The ID parameter specifies an authorization field (in the authorization object).
The FIELD parameter specifies a value for the authorization field.
The authorization object and its fields have to be suitable for the transaction. In most cases you will be able to use the existing authorization objects to protect your data. But new developments may require that you define new authorization objects and fields.
http://help.sap.com/saphelp_nw04s/helpdata/en/52/67167f439b11d1896f0000e8322d00/content.htm
To ensure that a user has the appropriate authorizations when he or she performs an action, users are subject to authorization checks.
Authorization : An authorization enables you to perform a particular activity in the SAP System, based on a set of authorization object field values.
You program the authorization check using the ABAP statement AUTHORITY-CHECK.
AUTHORITY-CHECK OBJECT 'S_TRVL_BKS'
ID 'ACTVT' FIELD '02'
ID 'CUSTTYPE' FIELD 'B'.
IF SY-SUBRC <> 0.
MESSAGE E...
ENDIF.
'S_TRVL_BKS' is a auth. object
ID 'ACTVT' FIELD '02' in place 2 you can put 1,2, 3 for change create or display.
The AUTHORITY-CHECK checks whether a user has the appropriate authorization to execute a particular activity.
This Authorization concept is somewhat linked with BASIS people.
As a developer you may not have access to access to SU21 Transaction where you have to define, authorizations, Objects and for nthat object you assign fields and values. Another Tcode is PFCG where you can assign these authrization objects and TCodes for a profile and that profile in turn attached to a particular user.
Take the help of the basis Guy and create and use.
Sy-SUBRC values
4 User has no authorization in the SAP System for
such an action. If necessary, change the user
master record.
8 Too many parameters (fields, values). Maximum
allowed is 10.
12 Specified object not maintained in the user
master record.
16 No profile entered in the user master record.
24 The field names of the check call do not match
those of an authorization. Either the
authorization or the call is incorrect.
28 Incorrect structure for user master record.
32 Incorrect structure for user master record.
36 Incorrect structure for user master record.
with regards,
Hema Sundara.
pls reward if u find it helpful. -
Authorization for tax code in PO
Hi,
I have one issue from the client. In Po creation (ME21N), they want to restrict some users to enter only few tax codes from among the list. For example if there are 30 tax codes, then user should be authorised to enter only 5 tax codes from the list. In standard authorization, there doesn't exist an authorization object to restrict tax codes.
For this I have created a Z-authorization object with authorization field (MWSKZ), in the user profile this authorization object has been assigned.
I am stuck at coding the authorization object means calling this object whenever the user creates the PO. Can you pls guide me on this?
Regards,
pankajHi
Hi See the following and do accordingly In general different users will be given different authorizations based on their role in the orgn. We create ROLES and assign the Authorization and TCODES for that role, so only that user can have access to those T Codes. USe SUIM and SU21 T codes for this. Much of the data in an R/3 system has to be protected so that unauthorized users cannot access it. Therefore the appropriate authorization is required before a user can carry out certain actions in the system. When you log on to the R/3 system, the system checks in the user master record to see which transactions you are authorized to use. An authorization check is implemented for every sensitive transaction. If you wish to protect a transaction that you have programmed yourself, then you must implement an authorization check. This means you have to allocate an authorization object in the definition of the transaction. For example: program an AUTHORITY-CHECK. AUTHORITY-CHECK OBJECT ID FIELD . ID FIELD . ... ID FIELD . The OBJECT parameter specifies the authorization object. The ID parameter specifies an authorization field (in the authorization object). The FIELD parameter specifies a value for the authorization field. The authorization object and its fields have to be suitable for the transaction. In most cases you will be able to use the existing authorization objects to protect your data. But new developments may require that you define new authorization objects and fields.
http://help.sap.com/saphelp_nw04s/helpdata/en/52/67167f439b11d1896f0000e8322d00/content.htm
To ensure that a user has the appropriate authorizations when he or she performs an action, users are subject to authorization checks. Authorization : An authorization enables you to perform a particular activity in the SAP System, based on a set of authorization object field values. You program the authorization check using the ABAP statement AUTHORITY-CHECK. AUTHORITY-CHECK OBJECT 'S_TRVL_BKS' ID 'ACTVT' FIELD '02' ID 'CUSTTYPE' FIELD 'B'. IF SY-SUBRC 0. MESSAGE E... ENDIF. 'S_TRVL_BKS' is a auth. object ID 'ACTVT' FIELD '02' in place 2 you can put 1,2, 3 for change create or display. The AUTHORITY-CHECK checks whether a user has the appropriate authorization to execute a particular activity. This Authorization concept is somewhat linked with BASIS people. As a developer you may not have access to access to SU21 Transaction where you have to define, authorizations, Objects and for nthat object you assign fields and values. Another Tcode is PFCG where you can assign these authrization objects and TCodes for a profile and that profile in turn attached to a particular user. Take the help of the basis Guy and create and use. -
Authorization for Table Maintance
Hi friends,
i need some help ....
i created table maintanence.Now all users are creating and deleting table entries.
wht is my problem is ..
Only particular users will do create and change .....and remaining users will use for display.
How i can set it ...Plaese tell me...the steps.
thanks,
kumarhai,
it may help u.
In general different users will be given different authorizations based on their role in the orgn.
We create ROLES and assign the Authorization and TCODES for that role, so only that user can have access to those T Codes.
USe SUIM and SU21 T codes for this.
Much of the data in an R/3 system has to be protected so that unauthorized users cannot access it. Therefore the appropriate authorization is required before a user can carry out certain actions in the system. When you log on to the R/3 system, the system checks in the user master record to see which transactions you are authorized to use. An authorization check is implemented for every sensitive transaction.
If you wish to protect a transaction that you have programmed yourself, then you must implement an authorization check.
This means you have to allocate an authorization object in the definition of the transaction.
For example:
program an AUTHORITY-CHECK.
AUTHORITY-CHECK OBJECT <authorization object>
ID <authority field 1> FIELD <field value 1>.
ID <authority field 2> FIELD <field value 2>.
ID <authority-field n> FIELD <field value n>.
The OBJECT parameter specifies the authorization object.
The ID parameter specifies an authorization field (in the authorization object).
The FIELD parameter specifies a value for the authorization field.
The authorization object and its fields have to be suitable for the transaction. In most cases you will be able to use the existing authorization objects to protect your data. But new developments may require that you define new authorization objects and fields.
http://help.sap.com/saphelp_nw04s/helpdata/en/52/67167f439b11d1896f0000e8322d00/content.htm
To ensure that a user has the appropriate authorizations when he or she performs an action, users are subject to authorization checks.
Authorization : An authorization enables you to perform a particular activity in the SAP System, based on a set of authorization object field values.
You program the authorization check using the ABAP statement AUTHORITY-CHECK.
AUTHORITY-CHECK OBJECT 'S_TRVL_BKS'
ID 'ACTVT' FIELD '02'
ID 'CUSTTYPE' FIELD 'B'.
IF SY-SUBRC <> 0.
MESSAGE E...
ENDIF.
'S_TRVL_BKS' is a auth. object
ID 'ACTVT' FIELD '02' in place 2 you can put 1,2, 3 for change create or display.
The AUTHORITY-CHECK checks whether a user has the appropriate authorization to execute a particular activity.
This Authorization concept is somewhat linked with BASIS people.
As a developer you may not have access to access to SU21 Transaction where you have to define, authorizations, Objects and for nthat object you assign fields and values. Another Tcode is PFCG where you can assign these authrization objects and TCodes for a profile and that profile in turn attached to a particular user.
Take the help of the basis Guy and create and use.
Sy-SUBRC values
4 User has no authorization in the SAP System for
such an action. If necessary, change the user
master record.
8 Too many parameters (fields, values). Maximum
allowed is 10.
12 Specified object not maintained in the user
master record.
16 No profile entered in the user master record.
24 The field names of the check call do not match
those of an authorization. Either the
authorization or the call is incorrect.
28 Incorrect structure for user master record.
32 Incorrect structure for user master record.
36 Incorrect structure for user master record.
check links.
http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ed2d446011d189700000e8322d00/content.htm
http://help.sap.com/saphelp_46c/helpdata/en/a7/5133ac407a11d1893b0000e8323c4f/frameset.htm
/message/2831202#2831202 [original link is broken]
sowjanya.b -
Need to create a driver class for a program i have made...
hey guys im new to these forums and someone told me that i could get help on here if i get in a bind...my problem is that i need help creating a driver class for a program that i have created and i dont know what to do. i need to know how to do this is because my professor told us after i was 2/3 done my project that we need at least 2 class files for our project, so i need at least 2 class files for it to run... my program is as follows:
p.s might be kinda messy, might need to put it into a text editor
Cipher.java
This program encodes and decodes text strings using a cipher that
can be specified by the user.
import java.io.*;
public class Cipher
public static void printID()
// output program ID
System.out.println ("*********************");
System.out.println ("* Cipher *");
System.out.println ("* *");
System.out.println ("* *");
System.out.println ("* *");
System.out.println ("* CS 181-03 *");
System.out.println ("*********************");
public static void printMenu()
// output menu
System.out.println("\n\n****************************" +
"\n* 1. Set cipher code. *" +
"\n* 2. Encode text. *" +
"\n* 3. Decode coded text. *" +
"\n* 4. Exit the program *" +
"\n****************************");
public static String getText(BufferedReader input, String prompt)
throws IOException
// prompt the user and get their response
System.out.print(prompt);
return input.readLine();
public static int getInteger(BufferedReader input, String prompt)
throws IOException
// prompt and get response from user
String text = getText(input, prompt);
// convert it to an integer
return (new Integer(text).intValue());
public static String encode(String original, int offset)
// declare constants
final int ALPHABET_SIZE = 26; // used to wrap around A-Z
String encoded = ""; // base for string to return
char letter; // letter being processed
// convert message to upper case
original = original.toUpperCase();
// process each character of the message
for (int index = 0; index < original.length(); index++)
// get the letter and determine whether or not to
// add the cipher value
letter = original.charAt(index);
if (letter >='A' && letter <= 'Z')
// is A-Z, so add offset
// determine whether result will be out of A-Z range
if ((letter + offset) > 'Z') // need to wrap around to 'A'
letter = (char)(letter - ALPHABET_SIZE + offset);
else
if ((letter + offset) < 'A') // need to wrap around to 'Z'
letter = (char)(letter + ALPHABET_SIZE + offset);
else
letter = (char) (letter + offset);
// build encoded message string
encoded = encoded + letter;
return encoded;
public static String decode(String original, int offset)
// declare constants
final int ALPHABET_SIZE = 26; // used to wrap around A-Z
String decoded = ""; // base for string to return
char letter; // letter being processed
// make original message upper case
original = original.toUpperCase();
// process each letter of message
for (int index = 0; index < original.length(); index++)
// get letter and determine whether to subtract cipher value
letter = original.charAt(index);
if (letter >= 'A' && letter <= 'Z')
// is A-Z, so subtract cipher value
// determine whether result will be out of A-Z range
if ((letter - offset) < 'A') // wrap around to 'Z'
letter = (char)(letter + ALPHABET_SIZE - offset);
else
if ((letter - offset) > 'Z') // wrap around to 'A'
letter = (char)(letter - ALPHABET_SIZE - offset);
else
letter = (char) (letter - offset);
// build decoded message
decoded = decoded + letter;
return decoded;
// main controls flow throughout the program, presenting a
// menu of options the user.
public static void main (String[] args) throws IOException
// declare constants
final String PROMPT_CHOICE = "Enter your choice: ";
final String PROMPT_VALID = "\nYou must enter a number between 1" +
" and 4 to indicate your selection.\n";
final String PROMPT_CIPHER = "\nEnter the offset value for a caesar " +
"cipher: ";
final String PROMPT_ENCODE = "\nEnter the text to encode: ";
final String PROMPT_DECODE = "\nEnter the text to decode: ";
final String SET_STR = "1"; // selection of 1 at main menu
final String ENCODE_STR = "2"; // selection of 2 at main menu
final String DECODE_STR = "3"; // selection of 3 at main menu
final String EXIT_STR = "4"; // selection of 4 at main menu
final int SET = 1; // menu choice 1
final int ENCODE = 2; // menu choice 2
final int DECODE =3; // menu choice 4
final int EXIT = 4; // menu choice 3
final int ALPHABET_SIZE = 26; // number of elements in alphabet
// declare variables
boolean finished = false; // whether or not to exit program
String text; // input string read from keyboard
int choice; // menu choice selected
int offset = 0; // caesar cipher offset
// declare and instantiate input objects
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
// Display program identification
printID();
// until the user selects the exit option, display the menu
// and respond to the choice
do
// Display menu of options
printMenu();
// Prompt user for an option and read input
text = getText(input, PROMPT_CHOICE);
// While selection is not valid, prompt for correct info
while (!text.equals(SET_STR) && !text.equals(ENCODE_STR) &&
!text.equals(EXIT_STR) && !text.equals(DECODE_STR))
text = getText(input, PROMPT_VALID + PROMPT_CHOICE);
// convert choice to an integer
choice = new Integer(text).intValue();
// respond to the choice selected
switch(choice)
case SET:
// get the cipher value from the user and constrain to
// -25..0..25
offset = getInteger(input, PROMPT_CIPHER);
offset %= ALPHABET_SIZE;
break;
case ENCODE:
// get message to encode from user, and encode it using
// the current cipher value
text = getText(input, PROMPT_ENCODE);
text = encode(text, offset);
System.out.println("Encoded text is: " + text);
break;
case DECODE:
// get message to decode from user, and decode it using
// the current cipher value
text = getText(input, PROMPT_DECODE);
text = decode(text, offset);
System.out.println("Decoded text is: " + text);
break;
case EXIT:
// set exit flag to true
finished = true ;
break;
} // end of switch on choice
} while (!finished); // end of outer do loop
// Thank user
System.out.println("Thank you for using Cipher for all your" +
" code breaking and code making needs.");
}My source in code format...sorry guys :)
Cipher.java
This program encodes and decodes text strings using a cipher that
can be specified by the user.
import java.io.*;
public class Cipher
public static void printID()
// output program ID
System.out.println ("*********************");
System.out.println ("* Cipher *");
System.out.println ("* *");
System.out.println ("* *");
System.out.println ("* *");
System.out.println ("* CS 181-03 *");
System.out.println ("*********************");
public static void printMenu()
// output menu
System.out.println("\n\n****************************" +
"\n* 1. Set cipher code. *" +
"\n* 2. Encode text. *" +
"\n* 3. Decode coded text. *" +
"\n* 4. Exit the program *" +
"\n****************************");
public static String getText(BufferedReader input, String prompt)
throws IOException
// prompt the user and get their response
System.out.print(prompt);
return input.readLine();
public static int getInteger(BufferedReader input, String prompt)
throws IOException
// prompt and get response from user
String text = getText(input, prompt);
// convert it to an integer
return (new Integer(text).intValue());
public static String encode(String original, int offset)
// declare constants
final int ALPHABET_SIZE = 26; // used to wrap around A-Z
String encoded = ""; // base for string to return
char letter; // letter being processed
// convert message to upper case
original = original.toUpperCase();
// process each character of the message
for (int index = 0; index < original.length(); index++)
// get the letter and determine whether or not to
// add the cipher value
letter = original.charAt(index);
if (letter >='A' && letter <= 'Z')
// is A-Z, so add offset
// determine whether result will be out of A-Z range
if ((letter + offset) > 'Z') // need to wrap around to 'A'
letter = (char)(letter - ALPHABET_SIZE + offset);
else
if ((letter + offset) < 'A') // need to wrap around to 'Z'
letter = (char)(letter + ALPHABET_SIZE + offset);
else
letter = (char) (letter + offset);
// build encoded message string
encoded = encoded + letter;
return encoded;
public static String decode(String original, int offset)
// declare constants
final int ALPHABET_SIZE = 26; // used to wrap around A-Z
String decoded = ""; // base for string to return
char letter; // letter being processed
// make original message upper case
original = original.toUpperCase();
// process each letter of message
for (int index = 0; index < original.length(); index++)
// get letter and determine whether to subtract cipher value
letter = original.charAt(index);
if (letter >= 'A' && letter <= 'Z')
// is A-Z, so subtract cipher value
// determine whether result will be out of A-Z range
if ((letter - offset) < 'A') // wrap around to 'Z'
letter = (char)(letter + ALPHABET_SIZE - offset);
else
if ((letter - offset) > 'Z') // wrap around to 'A'
letter = (char)(letter - ALPHABET_SIZE - offset);
else
letter = (char) (letter - offset);
// build decoded message
decoded = decoded + letter;
return decoded;
// main controls flow throughout the program, presenting a
// menu of options the user.
public static void main (String[] args) throws IOException
// declare constants
final String PROMPT_CHOICE = "Enter your choice: ";
final String PROMPT_VALID = "\nYou must enter a number between 1" +
" and 4 to indicate your selection.\n";
final String PROMPT_CIPHER = "\nEnter the offset value for a caesar " +
"cipher: ";
final String PROMPT_ENCODE = "\nEnter the text to encode: ";
final String PROMPT_DECODE = "\nEnter the text to decode: ";
final String SET_STR = "1"; // selection of 1 at main menu
final String ENCODE_STR = "2"; // selection of 2 at main menu
final String DECODE_STR = "3"; // selection of 3 at main menu
final String EXIT_STR = "4"; // selection of 4 at main menu
final int SET = 1; // menu choice 1
final int ENCODE = 2; // menu choice 2
final int DECODE =3; // menu choice 4
final int EXIT = 4; // menu choice 3
final int ALPHABET_SIZE = 26; // number of elements in alphabet
// declare variables
boolean finished = false; // whether or not to exit program
String text; // input string read from keyboard
int choice; // menu choice selected
int offset = 0; // caesar cipher offset
// declare and instantiate input objects
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
// Display program identification
printID();
// until the user selects the exit option, display the menu
// and respond to the choice
do
// Display menu of options
printMenu();
// Prompt user for an option and read input
text = getText(input, PROMPT_CHOICE);
// While selection is not valid, prompt for correct info
while (!text.equals(SET_STR) && !text.equals(ENCODE_STR) &&
!text.equals(EXIT_STR) && !text.equals(DECODE_STR))
text = getText(input, PROMPT_VALID + PROMPT_CHOICE);
// convert choice to an integer
choice = new Integer(text).intValue();
// respond to the choice selected
switch(choice)
case SET:
// get the cipher value from the user and constrain to
// -25..0..25
offset = getInteger(input, PROMPT_CIPHER);
offset %= ALPHABET_SIZE;
break;
case ENCODE:
// get message to encode from user, and encode it using
// the current cipher value
text = getText(input, PROMPT_ENCODE);
text = encode(text, offset);
System.out.println("Encoded text is: " + text);
break;
case DECODE:
// get message to decode from user, and decode it using
// the current cipher value
text = getText(input, PROMPT_DECODE);
text = decode(text, offset);
System.out.println("Decoded text is: " + text);
break;
case EXIT:
// set exit flag to true
finished = true ;
break;
} // end of switch on choice
} while (!finished); // end of outer do loop
// Thank user
System.out.println("Thank you for using Cipher for all your" +
" code breaking and code making needs.");
}
Maybe you are looking for
-
How to connect apple tv to NAD T748 AV Receiver
Hi All, Trying to connect apple tv to NAD T748 home theatre. Any one achieved this?
-
i have the new version of i tunes and it says it cannot ascess my ipad4 and asks to upgrade and reset how to solve this????
-
How do I get Dreamweaver to display pixel height as well?
When i click something in the display pane I would love for it to display the height as well as the width (590 in attached picture example). Any way to do this?
-
Not able to Find Some BOM Related Standard Data Sources in PP.
Dear Gurus, I am not able to find the Standard Data Sources for Loading the Master Data for the Following Standard Info Objects 1. 0BOM 2. 0COMPONENT 3. 0HG_LV_ITEM I have activated the objects in BW side, but not able to find the data sour
-
Photoshop cc download problems.
I'm trying to download the free trial of Photoshop cc, but every time i try to download it, it immediately fails.. Do i have something blocking me from downloading Photoshop or what?